Skip to content

Commit

Permalink
improved example and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Dec 12, 2024
1 parent 8036587 commit 1773449
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packages/share_plus/share_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,25 @@ class DemoAppState extends State<DemoApp> {
void _onShareXFileFromAssets(BuildContext context) async {
final box = context.findRenderObject() as RenderBox?;
final scaffoldMessenger = ScaffoldMessenger.of(context);
final data = await rootBundle.load('assets/flutter_logo.png');
final buffer = data.buffer;
final shareResult = await Share.shareXFiles(
[
XFile.fromData(
buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
name: 'flutter_logo.png',
mimeType: 'image/png',
),
],
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);

scaffoldMessenger.showSnackBar(getResultSnackBar(shareResult));
try {
final data = await rootBundle.load('assets/flutter_logo.png');
final buffer = data.buffer;
final shareResult = await Share.shareXFiles(
[
XFile.fromData(
buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
name: 'flutter_logo.png',
mimeType: 'image/png',
),
],
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
scaffoldMessenger.showSnackBar(getResultSnackBar(shareResult));
} catch (e) {
scaffoldMessenger.showSnackBar(
SnackBar(content: Text('Error: $e')),
);
}
}

void _onShareTextAsXFile(BuildContext context) async {
Expand Down
1 change: 1 addition & 0 deletions packages/share_plus/share_plus/lib/src/share_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class SharePlusWebPlugin extends SharePlatform {
List<XFile> files,
List<String>? fileNameOverrides,
) async {
developer.log('Download files as fallback');
try {
for (final (index, file) in files.indexed) {
final bytes = await file.readAsBytes();
Expand Down

0 comments on commit 1773449

Please sign in to comment.