This repository was archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathmain.dart
More file actions
151 lines (137 loc) · 4.45 KB
/
Copy pathmain.dart
File metadata and controls
151 lines (137 loc) · 4.45 KB
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:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
void main() => runApp(MaterialApp(
home: MaterialApp(
home: MyHomePage(),
),
));
class MyHomePage extends StatefulWidget {
MyHomePage();
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Share Example'),
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
MaterialButton(
child: Text('Share text'),
onPressed: () async => await _shareText(),
),
MaterialButton(
child: Text('Share image'),
onPressed: () async => await _shareImage(),
),
MaterialButton(
child: Text('Share images'),
onPressed: () async => await _shareImages(),
),
MaterialButton(
child: Text('Share CSV'),
onPressed: () async => await _shareCSV(),
),
MaterialButton(
child: Text('Share mixed'),
onPressed: () async => await _shareMixed(),
),
MaterialButton(
child: Text('Share image from url'),
onPressed: () async => await _shareImageFromUrl(),
),
MaterialButton(
child: Text('Share sound'),
onPressed: () async => await _shareSound(),
),
],
)));
}
Future<void> _shareText() async {
try {
Share.text(
'my text title', 'This is my text to share with other applications.', 'text/plain');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareImage() async {
try {
final ByteData bytes = await rootBundle.load('assets/image1.png');
await Share.file('esys image', 'esys.png', bytes.buffer.asUint8List(), 'image/png',
text: 'My optional text.');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareImages() async {
try {
final ByteData bytes1 = await rootBundle.load('assets/image1.png');
final ByteData bytes2 = await rootBundle.load('assets/image2.png');
await Share.files(
'esys images',
{
'esys.png': bytes1.buffer.asUint8List(),
'bluedan.png': bytes2.buffer.asUint8List(),
},
'image/png');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareCSV() async {
try {
final ByteData bytes = await rootBundle.load('assets/addresses.csv');
await Share.file('addresses', 'addresses.csv', bytes.buffer.asUint8List(), 'text/csv');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareMixed() async {
try {
final ByteData bytes1 = await rootBundle.load('assets/image1.png');
final ByteData bytes2 = await rootBundle.load('assets/image2.png');
final ByteData bytes3 = await rootBundle.load('assets/addresses.csv');
await Share.files(
'esys images',
{
'esys.png': bytes1.buffer.asUint8List(),
'bluedan.png': bytes2.buffer.asUint8List(),
'addresses.csv': bytes3.buffer.asUint8List(),
},
'*/*',
text: 'My optional text.');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareImageFromUrl() async {
try {
var request = await HttpClient().getUrl(
Uri.parse('https://shop.esys.eu/media/image/6f/8f/af/amlog_transport-berwachung.jpg'));
var response = await request.close();
Uint8List bytes = await consolidateHttpClientResponseBytes(response);
await Share.file('ESYS AMLOG', 'amlog.jpg', bytes, 'image/jpg');
} catch (e) {
print('error: $e');
}
}
Future<void> _shareSound() async {
try {
final ByteData bytes = await rootBundle.load('assets/cat.mp3');
await Share.file('Sound', 'cat.mp3', bytes.buffer.asUint8List(), 'audio/*');
} catch (e) {
print('error: $e');
}
}
}