У меня есть простое приложение для камеры, которое я сделал, и я хочу поделиться своим изображением с другими с помощью Share. Однако, когда я запускаю следующий код, он просто разделяет путь к картинке:
Share.share(imagePath);
Может кто-нибудь сказать, пожалуйста, как это сделать? Я думаю, вам нужно как-то преобразовать биты. Спасибо!
Вот еще код для справки:
class DisplayPictureScreen extends StatelessWidget {
final String imagePath;
Future<ByteData> getBytesFromFile() async {
Uint8List bytes = File(imagePath).readAsBytesSync() as Uint8List;
return ByteData.view(bytes.buffer);
}
const DisplayPictureScreen({Key key, this.imagePath}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Display the Picture')),
// The image is stored as a file on the device. Use the `Image.file`
// constructor with the given path to display the image.
body: Image.file(File(imagePath)),
floatingActionButton: FloatingActionButton(
onPressed: () {
print("in print");
Share.share(imagePath);
/*
getBytesFromFile().then((bytes) {
Share.file('Share via:', imagePath,
bytes.buffer.asUint8List(), 'image/png');
});
*/}
)
);
}
}