-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'dart:async'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart'; | ||
import 'package:flutter_sharing_intent/model/sharing_file.dart'; | ||
|
||
class ShareReceive extends StatefulWidget { | ||
const ShareReceive({super.key}); | ||
|
||
@override | ||
State<ShareReceive> createState() => _ShareReceiveState(); | ||
} | ||
|
||
class _ShareReceiveState extends State<ShareReceive> { | ||
late StreamSubscription _intentDataStreamSubscription; | ||
List<SharedFile>? list; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
// For sharing images coming from outside the app while the app is in | ||
// the memory | ||
_intentDataStreamSubscription = FlutterSharingIntent.instance.getMediaStream() | ||
.listen((sharedFiles) { | ||
setState(() { | ||
list = sharedFiles; | ||
}); | ||
// ignore: avoid_print | ||
print( | ||
"Shared: getMediaStream ${sharedFiles.map((f) => f.value).join(",")}"); | ||
}, onError: (err) { | ||
// ignore: avoid_print | ||
print('getIntentDataStream error: $err'); | ||
}); | ||
|
||
// For sharing images coming from outside the app while the app is closed | ||
FlutterSharingIntent.instance.getInitialSharing().then((sharedFiles) { | ||
// ignore: avoid_print | ||
print( | ||
"Shared: getInitialMedia ${sharedFiles.map((f) => f.value).join(",")}"); | ||
setState(() { | ||
list = sharedFiles; | ||
}); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Plugin example app'), | ||
), | ||
body: Center( | ||
child: Container( | ||
margin: EdgeInsets.symmetric(horizontal: 24), | ||
child: Text('Sharing data: \n${list?.join("\n\n")}\n')), | ||
), | ||
), | ||
); | ||
} | ||
@override | ||
void dispose() { | ||
_intentDataStreamSubscription.cancel(); | ||
super.dispose(); | ||
} | ||
} |