diff --git a/packages/share_plus/share_plus/example/ios/Flutter/AppFrameworkInfo.plist b/packages/share_plus/share_plus/example/ios/Flutter/AppFrameworkInfo.plist
index 3a9c234f96..9b41e7d879 100644
--- a/packages/share_plus/share_plus/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/packages/share_plus/share_plus/example/ios/Flutter/AppFrameworkInfo.plist
@@ -25,6 +25,6 @@
arm64
MinimumOSVersion
- 9.0
+ 11.0
diff --git a/packages/share_plus/share_plus/example/ios/Runner.xcodeproj/project.pbxproj b/packages/share_plus/share_plus/example/ios/Runner.xcodeproj/project.pbxproj
index f7301ad7a7..05955131ac 100644
--- a/packages/share_plus/share_plus/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/packages/share_plus/share_plus/example/ios/Runner.xcodeproj/project.pbxproj
@@ -333,7 +333,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -383,7 +383,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
diff --git a/packages/share_plus/share_plus/example/lib/image_previews.dart b/packages/share_plus/share_plus/example/lib/image_previews.dart
index 97e531409b..f46cc7648f 100644
--- a/packages/share_plus/share_plus/example/lib/image_previews.dart
+++ b/packages/share_plus/share_plus/example/lib/image_previews.dart
@@ -19,7 +19,7 @@ class ImagePreviews extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (imagePaths.isEmpty) {
- return Container();
+ return const SizedBox.shrink();
}
final imageWidgets = [];
diff --git a/packages/share_plus/share_plus/example/lib/main.dart b/packages/share_plus/share_plus/example/lib/main.dart
index 4d998bb55b..99d63889cd 100644
--- a/packages/share_plus/share_plus/example/lib/main.dart
+++ b/packages/share_plus/share_plus/example/lib/main.dart
@@ -37,110 +37,129 @@ class DemoAppState extends State {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Share Plus Plugin Demo',
+ theme: ThemeData(
+ useMaterial3: true,
+ colorSchemeSeed: const Color(0x9f4376f8),
+ ),
home: Scaffold(
- appBar: AppBar(
- title: const Text('Share Plus Plugin Demo'),
- ),
- body: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.all(24.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- TextField(
- decoration: const InputDecoration(
- labelText: 'Share text:',
- hintText: 'Enter some text and/or link to share',
+ appBar: AppBar(
+ title: const Text('Share Plus Plugin Demo'),
+ ),
+ body: SingleChildScrollView(
+ padding: const EdgeInsets.all(24),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ TextField(
+ decoration: const InputDecoration(
+ border: OutlineInputBorder(),
+ labelText: 'Share text',
+ hintText: 'Enter some text and/or link to share',
+ ),
+ maxLines: null,
+ onChanged: (String value) => setState(() {
+ text = value;
+ }),
+ ),
+ const SizedBox(height: 16),
+ TextField(
+ decoration: const InputDecoration(
+ border: OutlineInputBorder(),
+ labelText: 'Share subject',
+ hintText: 'Enter subject to share (optional)',
+ ),
+ maxLines: null,
+ onChanged: (String value) => setState(() {
+ subject = value;
+ }),
+ ),
+ const SizedBox(height: 16),
+ ImagePreviews(imagePaths, onDelete: _onDeleteImage),
+ ElevatedButton.icon(
+ label: const Text('Add image'),
+ onPressed: () async {
+ // Using `package:image_picker` to get image from gallery.
+ if (Platform.isMacOS ||
+ Platform.isLinux ||
+ Platform.isWindows) {
+ // Using `package:file_selector` on windows, macos & Linux, since `package:image_picker` is not supported.
+ const XTypeGroup typeGroup = XTypeGroup(
+ label: 'images',
+ extensions: ['jpg', 'jpeg', 'png', 'gif'],
+ );
+ final file = await openFile(
+ acceptedTypeGroups: [typeGroup]);
+ if (file != null) {
+ setState(() {
+ imagePaths.add(file.path);
+ imageNames.add(file.name);
+ });
+ }
+ } else {
+ final imagePicker = ImagePicker();
+ final pickedFile = await imagePicker.pickImage(
+ source: ImageSource.gallery,
+ );
+ if (pickedFile != null) {
+ setState(() {
+ imagePaths.add(pickedFile.path);
+ imageNames.add(pickedFile.name);
+ });
+ }
+ }
+ },
+ icon: const Icon(Icons.add),
+ ),
+ const SizedBox(height: 32),
+ Builder(
+ builder: (BuildContext context) {
+ return ElevatedButton(
+ style: ElevatedButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onPrimary,
+ backgroundColor: Theme.of(context).colorScheme.primary,
),
- maxLines: 2,
- onChanged: (String value) => setState(() {
- text = value;
- }),
- ),
- TextField(
- decoration: const InputDecoration(
- labelText: 'Share subject:',
- hintText: 'Enter subject to share (optional)',
+ onPressed: text.isEmpty && imagePaths.isEmpty
+ ? null
+ : () => _onShare(context),
+ child: const Text('Share'),
+ );
+ },
+ ),
+ const SizedBox(height: 16),
+ Builder(
+ builder: (BuildContext context) {
+ return ElevatedButton(
+ style: ElevatedButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onPrimary,
+ backgroundColor: Theme.of(context).colorScheme.primary,
),
- maxLines: 2,
- onChanged: (String value) => setState(() {
- subject = value;
- }),
- ),
- const Padding(padding: EdgeInsets.only(top: 12.0)),
- ImagePreviews(imagePaths, onDelete: _onDeleteImage),
- ListTile(
- leading: const Icon(Icons.add),
- title: const Text('Add image'),
- onTap: () async {
- // Using `package:image_picker` to get image from gallery.
- if (Platform.isMacOS ||
- Platform.isLinux ||
- Platform.isWindows) {
- // Using `package:file_selector` on windows, macos & Linux, since `package:image_picker` is not supported.
- const XTypeGroup typeGroup = XTypeGroup(
- label: 'images',
- extensions: ['jpg', 'jpeg', 'png', 'gif'],
- );
- final file = await openFile(
- acceptedTypeGroups: [typeGroup]);
- if (file != null) {
- setState(() {
- imagePaths.add(file.path);
- imageNames.add(file.name);
- });
- }
- } else {
- final imagePicker = ImagePicker();
- final pickedFile = await imagePicker.pickImage(
- source: ImageSource.gallery,
- );
- if (pickedFile != null) {
- setState(() {
- imagePaths.add(pickedFile.path);
- imageNames.add(pickedFile.name);
- });
- }
- }
- },
- ),
- const Padding(padding: EdgeInsets.only(top: 12.0)),
- Builder(
- builder: (BuildContext context) {
- return ElevatedButton(
- onPressed: text.isEmpty && imagePaths.isEmpty
- ? null
- : () => _onShare(context),
- child: const Text('Share'),
- );
- },
- ),
- const Padding(padding: EdgeInsets.only(top: 12.0)),
- Builder(
- builder: (BuildContext context) {
- return ElevatedButton(
- onPressed: text.isEmpty && imagePaths.isEmpty
- ? null
- : () => _onShareWithResult(context),
- child: const Text('Share With Result'),
- );
- },
- ),
- const Padding(padding: EdgeInsets.only(top: 12.0)),
- Builder(
- builder: (BuildContext context) {
- return ElevatedButton(
- onPressed: () {
- _onShareXFileFromAssets(context);
- },
- child: const Text('Share XFile from Assets'),
- );
+ onPressed: text.isEmpty && imagePaths.isEmpty
+ ? null
+ : () => _onShareWithResult(context),
+ child: const Text('Share With Result'),
+ );
+ },
+ ),
+ const SizedBox(height: 16),
+ Builder(
+ builder: (BuildContext context) {
+ return ElevatedButton(
+ style: ElevatedButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onPrimary,
+ backgroundColor: Theme.of(context).colorScheme.primary,
+ ),
+ onPressed: () {
+ _onShareXFileFromAssets(context);
},
- ),
- ],
+ child: const Text('Share XFile from Assets'),
+ );
+ },
),
- ),
- )),
+ ],
+ ),
+ ),
+ ),
);
}
@@ -180,24 +199,22 @@ class DemoAppState extends State {
void _onShareWithResult(BuildContext context) async {
final box = context.findRenderObject() as RenderBox?;
final scaffoldMessenger = ScaffoldMessenger.of(context);
- ShareResult result;
+ ShareResult shareResult;
if (imagePaths.isNotEmpty) {
final files = [];
for (var i = 0; i < imagePaths.length; i++) {
files.add(XFile(imagePaths[i], name: imageNames[i]));
}
- result = await Share.shareXFiles(files,
+ shareResult = await Share.shareXFiles(files,
text: text,
subject: subject,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
} else {
- result = await Share.shareWithResult(text,
+ shareResult = await Share.shareWithResult(text,
subject: subject,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
}
- scaffoldMessenger.showSnackBar(SnackBar(
- content: Text("Share result: ${result.status}"),
- ));
+ scaffoldMessenger.showSnackBar(getResultSnackBar(shareResult));
}
void _onShareXFileFromAssets(BuildContext context) async {
@@ -205,18 +222,31 @@ class DemoAppState extends State {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final data = await rootBundle.load('assets/flutter_logo.png');
final buffer = data.buffer;
- final result = await Share.shareXFiles(
+ final shareResult = await Share.shareXFiles(
[
XFile.fromData(
- buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
- name: 'flutter_logo.png',
- mimeType: 'image/png'),
+ buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
+ name: 'flutter_logo.png',
+ mimeType: 'image/png',
+ ),
],
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
- scaffoldMessenger.showSnackBar(SnackBar(
- content: Text("Share result: ${result.status}"),
- ));
+ scaffoldMessenger.showSnackBar(getResultSnackBar(shareResult));
+ }
+
+ SnackBar getResultSnackBar(ShareResult result) {
+ return SnackBar(
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text("Share result: ${result.status}"),
+ if (result.status == ShareResultStatus.success)
+ Text("Shared to: ${result.raw}")
+ ],
+ ),
+ );
}
}