-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.dart
151 lines (143 loc) · 6.29 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:ui';
import 'package:share_files_and_screenshot_widgets/share_files_and_screenshot_widgets.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter ScreenShot Demo',
theme: ThemeData(
primarySwatch: Colors.deepOrange,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo ScreenShot Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Image _image;
GlobalKey previewContainer = new GlobalKey();
int originalSize = 800;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
RepaintBoundary(
key: previewContainer,
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 1.5),
borderRadius: BorderRadius.circular(20),
color: Colors.deepPurple),
padding: EdgeInsets.all(15),
margin: EdgeInsets.all(20),
width: MediaQuery.of(context).size.width - 40,
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
"This is a picture.",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Image.asset("assets/example.jpg"),
Text(
"There’s something so whimsical about these beautiful images that incorporate bokeh. It’s almost as if they could be from a different, magical world. We’ve loved watching the submissions fly in for our bokeh-themed Photo Quest by Meyer-Optik-Görlitz and selected 30+ of our favourites beautiful images to ignite your creative spark! The three lucky winners of this Quest are going to receive an incredible prize courtesy of master lens-crafters Meyer-Optik.",
style: TextStyle(color: Colors.white),
),
],
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
child: ElevatedButton(
child: Text("Take Screenshot!"),
onPressed: () {
ShareFilesAndScreenshotWidgets()
.takeScreenshot(previewContainer, originalSize)
.then((Image value) {
setState(() {
_image = value;
});
});
}),
),
Container(
child: ElevatedButton(
child: Text("Share Screenshot!"),
onPressed: () {
ShareFilesAndScreenshotWidgets().shareScreenshot(
previewContainer,
originalSize,
"Title",
"Name.png",
"image/png",
text: "This is the caption!");
})),
Container(
child: ElevatedButton(
child: Text("Share Image!"),
onPressed: () async {
ByteData bytes =
await rootBundle.load('assets/example.jpg');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
"Title", "Name.jpg", list, "image/jpg",
text: "This is the caption!");
})),
Container(
child: ElevatedButton(
child: Text("Share Video!"),
onPressed: () async {
ByteData bytes =
await rootBundle.load('assets/example.mp4');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
"Title", "Name.mp4", list, "video/mp4",
text: "This is the caption!");
})),
Container(
child: ElevatedButton(
child: Text("Share Audio!"),
onPressed: () async {
ByteData bytes =
await rootBundle.load('assets/example.mp3');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
"Title", "Name.mp3", list, "audio/mp3",
text: "This is the caption!");
})),
],
),
_image != null ? _image : Center()
],
),
),
));
}
}