Flutter Share Widget as Screenshot
In this guide, we will learn how to implement the share screenshot of the widgets you want in Flutter by using the external package name share_widgets. This plugin allows Flutter apps to share screenshot. For example, when you are need share screenshot. this package will be share . In this example, we are going to show you how to share widget in Flutter. which is provided by the share_widgets package. Here’s an example of how you could use it:
Usage
First, add share_widgets
as a dependency in your pubspec.yaml file.
dependencies:
share_screenshot_widget: ^0.0.5
Don't forget to flutter pub get
.
Then import:
import 'package:share_screenshot_widget/share_screenshot_widget.dart';
Now you can Share Text As Image use its widget
class MyApp extends StatelessWidget {
const MyApp({super.key});
// add GlobalKey
final globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
// add widget ShareTextAsImage
return GestureDetector(
onTap: () {
shareWidgets( globalKey:globalKey);
},
child: ShareTextAsImage(globalKey:globalKey,
child: Text(
'Share Text As Image.',
),
),
);
}
}
Now you can Share Screenshot As Image use its widget
class MyApp extends StatelessWidget {
const MyApp({super.key});
// add GlobalKey
final globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
// add widget ShareScreenshotAsImage
return GestureDetector(
onTap: () {
sharing.shareWidgets();
},
child: ShareScreenshotAsImage(
globalKey:globalKey,
child: Text(
'Share Screenshot As Image.',
),
),
);
}
}
To Share widget as Screenshot
// add fun shareWidgets
shareWidgets();
To Share Sting
shareString(){
// fun shareString
shareString( text:"Share String", subject : 'subject');
}
To Share File
shareFile(){
// fun shareFile
shareFile(file: file, subject : 'subject');
}
Examples
Simple usage example can be found in the example folder.
Mobile platforms (Android and iOS)
Sharing widget as Screenshot in (WhatsApp,Telegram, Instagram, Facebook Messenger)
Contributing?
You're always welcome. See Contributing Guidelines. You can also take a look at Status Tracker to know more information about current or pending features/issues.