How to share a file using flutter

You can use the EsysFlutterShare Plugin. In version 1.0.0 you can share any file you like and its working on both, iOS and Android.

Just put that in yout pubspec.yaml:

dependencies:
  esys_flutter_share: ^1.0.0

Import the lib:

import 'package:esys_flutter_share/esys_flutter_share.dart';

Share a 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 privide a title, a file name, the file-bytes and a mime type.


I used share_extend combined with path_provider to share an audio file and it works perfectly.

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");
}

Tags:

Dart

Flutter