My flutter share button is running extremely slow. Reason I think is that it has to screenshot the image after getting from firebase for each specific news.(My Assumption)
Share button:
IconButton(
onPressed: () async {
final controller = ScreenshotController();
final bytes = await controller.captureFromWidget(
Material(
child: buildCard(
widget.data!.docs[widget.index!].get('url'),
widget.data!.docs[widget.index!].get('title'),
widget.data!.docs[widget.index!].get('body'),
widget.data!.docs[widget.index!].get('source'),
widget.data!.docs[widget.index!].get('link'),
context),
),
);
final temp = await getTemporaryDirectory();
final path = '${temp.path}/image.png';
File(path).writeAsBytesSync(bytes);
await Share.shareFiles([path],
text: 'Check out this awesome news \n\n');
},
icon: Icon(Icons.share))
BuildCard:
Widget buildCard(String imageUrl, String Title, String body, String source,
String newsLink, BuildContext context) {
final deviceHeight = MediaQuery.of(context).size.height;
final deviceWidth = MediaQuery.of(context).size.width;
return RepaintBoundary(
key: cardKey,
child: Stack(children: [
Container(
height: deviceHeight,
width: deviceWidth,
color: Color(0xFFf1f0e9),
),
Column(
children: [
Image.network(imageUrl),
Container(
margin: EdgeInsets.only(
left: 15,
right: 15,
top: 15,
),
child: Text(Title, style: GoogleFonts.openSans(fontSize: 20))),
SizedBox(
height: 0.001 * deviceHeight,
),
Container(
margin: EdgeInsets.all(15),
child: Text(body,
style: GoogleFonts.openSans(
fontWeight: FontWeight.w300, fontSize: 17)),
),
Row(
children: [
SizedBox(
width: 0.04 * deviceWidth,
),
Text('Source:$source ', style: TextStyle(fontSize: 10)),
SizedBox(
width: 0.3 * deviceWidth,
)
],
),
Row(
children: [
SizedBox(
width: 0.02 * deviceWidth,
),
TextButton(
onPressed: () async {
var link = newsLink;
var url = '$link';
if (await canLaunch(url)) {
await launch(url,
forceSafariVC: true,
forceWebView: true,
enableJavaScript: true);
}
},
child: Text('Read more')),
SizedBox(
width: 0.3 * deviceWidth,
),
],
),
],
),
]),
);
}
What I have tried:
I have tried several ways but can't find a way which is specific to me and help with my code as it should be a dynamic share.