'Share_plus with url without using path_provider in flutter web
I have this piece of code here that shows the image on a page with a button that could share this image to Facebook or any other social media site via url, right now most of the tutorials are asking me to use path_provider to store the bytes inside the local storage. However, i'm doing flutter web and the path_provider package does not support web, is there any alternatives to path_provider?
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'dart:html';
import 'package:http/http.dart' as http;
class ImageViewer extends StatefulWidget {
@override
State<ImageViewer> createState() => _ImageViewerState();
}
class _ImageViewerState extends State<ImageViewer> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Image title"),
),
body: Column(
children: [
AspectRatio(aspectRatio: 4/3,
child: Image.network('https://picsum.photos/seed/548/600')),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(icon: const Icon(Icons.arrow_upward),
tooltip: 'Upvote image',
onPressed: () {
},),
IconButton(icon: const Icon(Icons.arrow_downward),
tooltip: 'Downvote image',
onPressed: () {
},
),
IconButton(icon: const Icon(Icons.facebook),
tooltip: 'Downvote image',
onPressed: () async {
const urlImage = 'https://picsum.photos/seed/548/600';
final url = Uri.parse(urlImage);
final response = await http.get(url);
final bytes = response.bodyBytes;
// final temp = await ;
},
)
],
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Title'),
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Upvotes'),
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Description'),
),
],
),
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
