sunny_share 0.4.4+7
sunny_share: ^0.4.4+7 copied to clipboard
Plugin for creating more detailed share content
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sunny_share/sunny_share.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _value;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ListView(
children: [
_example1(),
const SizedBox(height: 8),
_imageExample(),
const SizedBox(height: 8),
_shareImageSecondary(),
const SizedBox(height: 8),
_exampleNoMetadata(),
const SizedBox(height: 8),
_examplePartialMetadata(),
const SizedBox(height: 8),
_example2(),
const SizedBox(height: 8),
_multipleContent(),
const SizedBox(height: 8),
ElevatedButton(
child: Text("Paste Clipboard"),
onPressed: () async {
final str = await Clipboard.getData(Clipboard.kTextPlain);
setState(() {
_value = str?.text;
});
},
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(child: Text(_value ?? "No text to display")),
),
],
),
),
),
);
}
Widget _example1() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.url(
"https://trippiapp.com/",
imageUrl:
"https://trippiapp.files.wordpress.com/2020/07/cropped-trippi-wordmark_black.png",
iconUrl:
"https://trippiapp.files.wordpress.com/2020/07/cropped-trippi-wordmark_black.png",
caption: "Check it out, dawg",
label: "This is the website I told you about. Check it out",
).variant(
clipboard,
ShareContent.text(
"This is the trippi website: https://www.trippiapp.com")),
// ShareItem.automatic(
// url: "https://www.trippiapp.com",
// content:
// "This is a another item. http://trippiapp.com",
// caption: "Trippi",
// ),
]).then((_) => print(_));
},
child: Text("Website"));
Widget _imageExample() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.image(
"https://upload.wikimedia.org/wikipedia/commons/e/e4/Picherconnell.jpg",
caption: "www.mysite.com",
label: "Swings in the Desert",
subject: "Read more about this",
)
]).then((_) => print(_));
},
child: Text("Share Image"));
Widget _shareImageSecondary() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.url(
"https://www.trippiapp.com",
imageUrl:
"https://upload.wikimedia.org/wikipedia/commons/e/e4/Picherconnell.jpg",
caption: "www.mysite.com",
label: "Swings in the Desert",
subject: "Read more about this",
),
ShareItem.image(
"https://upload.wikimedia.org/wikipedia/commons/e/e4/Picherconnell.jpg",
caption: "www.mysite.com",
label: "Swings in the Desert",
subject: "Read more about this",
),
]).then((_) => print(_));
},
child: Text("Text with Image"));
Widget _exampleNoMetadata() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.url("https://trippiapp.com/").variant(
clipboard,
ShareContent.text(
"This is the trippi website: https://www.trippiapp.com"),
),
// ShareItem.automatic(
// url: "https://www.trippiapp.com",
// content:
// "This is a another item. http://trippiapp.com",
// caption: "Trippi",
// ),
]).then((_) => print(_));
},
child: Text("Website without metadata"));
Widget _examplePartialMetadata() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.url(
"https://trippiapp.com/",
caption: "www.trippi.com",
label: "This website is a great place to go to",
imageUrl:
"https://trippiapp.files.wordpress.com/2020/07/cropped-trippi-wordmark_black.png",
).variant(
clipboard,
ShareContent.text(
"This is the trippi website: https://www.trippiapp.com")),
// ShareItem.automatic(
// url: "https://www.trippiapp.com",
// content:
// "This is a another item. http://trippiapp.com",
// caption: "Trippi",
// ),
]).then((_) => print(_));
},
child: Text("Website partial metadata"));
Widget _example2() => ElevatedButton(
onPressed: () async {
final res = await Share.share(items: [
ShareItem.text(
"Check out everything at https://www.trippiapp.com - you're gonna want to see this!!",
caption: "www.trippiapp.com",
label: "Karen's Trip to Oklahoma",
imageUrl:
"https://upload.wikimedia.org/wikipedia/commons/e/e4/Picherconnell.jpg",
)
.variant(
TargetAction.sendEmail,
ShareContent.html(
"<html><head></head><body><b>Check</b> out everything at <a href='https://www.trippiapp.com'>Trippi</a> - you're gonna want to see this!!</body></html>"))
.variant(
TargetAction.sendSms,
ShareContent.text(
"For SMS, you get something extra special: https://trippiapp.page.link/fred"),
)
.variant(
clipboard,
ShareContent.text(
"The clipboard has things: https://www.trippiapp.com/clipboard"),
)
]);
print(res);
},
child: Text("Share HTML"));
static const clipboard = TargetAction("clipboard",
iosName: "com.apple.UIKit.activity.CopyToPasteboard");
static const insta =
TargetAction("instagram", iosName: "com.instagram.share");
Widget _multipleContent() => ElevatedButton(
onPressed: () {
Share.share(items: [
ShareItem.url(
"https://www.trippiapp.com",
imageUrl:
"https://trippiapp.files.wordpress.com/2020/07/cropped-trippi-wordmark_black.png",
caption: "Food",
).variant(
clipboard,
ShareContent.url("https://clipboardcopy.com"),
),
ShareItem.text(
"Boring for boring people",
label: "Bore me",
).variant(
clipboard,
ShareContent.html(
"<html><body>HTML content goes to <a href='https://www.instagram.com'>Instagram</a></body></html>")),
ShareItem.image(
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Instagram_icon.png/1024px-Instagram_icon.png",
label: "This is an image",
),
]).then((_) {
print(_);
});
},
child: Text("Multiple Items"));
}