Reputation: 1798
What I'm trying to do is allow users to share a post they see on my app. I am using the Flutter Share plugin, but I'm having some difficulty with it and have been looking all over, including the docs which aren't very good.
I have the share button itself working - so the panel will rise up and be displayed to the user. However, it doesn't provide them with any useful option and I can't find how to add those options, such as Facebook, Twitter, Email, Text, etc..
Here is my code, and a picture to show what is happening:
// build method from another class
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection('stories').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) =>
_buildEventCards(context, snapshot.data.documents[index]),
);
},
);
}
class ShareButton extends StatelessWidget {
const ShareButton({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return FlatButton(
child: Text(
'Share',
style: TextStyle(
color: Color.fromRGBO(245, 93, 62, 1.0)),
),
color: Colors.grey[100],
onPressed: () {
final RenderBox box = context.findRenderObject();
Share.share('Hello this is a test',
sharePositionOrigin:
box.localToGlobal(Offset.zero) &
box.size);
},
);
}
}
Sorry the picture is so big, but I would like to add sharing options such as Facebook, Twitter, Email, Messages, etc.
Any help would be much appreciated!
Upvotes: 2
Views: 3820
Reputation: 1798
I feel kind of dumb now because I now realize how this Share thing works, but this is definitely something that could be confusing for beginners or people using simulators on their computers wondering what's happening..
Everything works fine the reason I couldn't get anything to show up in the Share panel is because I was testing with simulator app on my computer which doesn't have the mail app, isn't associated with my phone number, isn't logged into Facebook / Twitter, and doesn't have any other apps that could be shared through.
All you have to do is test your app on your actual device and then what ever apps / accounts you're logged into will show up here and you'll be able to share stuff.
Upvotes: 2