How to share a file using flutter

I am wondering how to share a file in a flutter application?

I saw some old references to using Intents with mojo, but this no longer seems to be present. This is similar to a standard function that we can handle in a cross-platform way (obviously, with some differences between ios and android).

What are the current guidelines for file sharing (e.g. email)? The closest I could appreciate is UrlLauncher, which I could imagine in order to run a handler for the file that I want to share, but it seems stretched.

+9
source share
6 answers

, , , , https://flutter.io/flutter-for-android/#how-do-i-handle-incoming- .

Günter Zöchbauer Gitter!

, , "" - , , , ,

+3

, .

flutter-share github, , , , Share , : Share.file(path: <String>, mimeType: ShareType, title:, text: ); mimeType, title text , share.

Android, IOS , Android ( ).

+2

You can use the EsysFlutterShare plugin . In version 1.0.0, you can share any file that you like, and it works on both iOS and Android.

Just put this in your pubspec.yaml:

dependencies:
  esys_flutter_share: ^1.0.0

Import the library:

import 'package:esys_flutter_share/esys_flutter_share.dart';

Share file:

final ByteData bytes = await rootBundle.load('assets/image1.png');
await Share.file('esys image', 'esys.png', bytes.buffer.asUint8List(), 'image/png');

You need to specify the name, file name, bytes and MIME type.

+2
source

I used share_extend to combine with path_provider to share the audio file and it works fine.

void share() async {
Directory dir = await getApplicationDocumentsDirectory();
File testFile = new File("${dir.path}/sound.m4a");
if (!await testFile.exists()) {
  await testFile.create(recursive: true);
  testFile.writeAsStringSync("test for share documents file");
}
ShareExtend.share(testFile.path, "file");

}

0
source

Source: https://habr.com/ru/post/1663673/


All Articles