My app has a button to share an image loaded from the Internet. The code is working fine on iOS.
– But on Android, the first attempt never works. rootBundle
throws an Exception(Unable to load asset).
The rootBundle
only finds the cached file after a hot restart, so release versions never work.
==> If I re-run the app, the problem vanishes until the next uninstall and reinstallation of the app.
I'm using the flutter-cache-manager and esys-flutter-share packages.
I also tried Flutter Clean. Flutter Upgrade. on dev/beta/master channels.
shareMedia(int index) async {
var file = await DefaultCacheManager().getSingleFile(imageLink);
final ByteData bytes = await rootBundle.load(file.path);
await Share.file('Hi !!', 'image.png', bytes.buffer.asUint8List(), 'image/png');
}
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.10.14, on Mac OS X 10.14.6 18G95, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.38.1)
[✓] Connected device (3 available)
• No issues found!
Any ideas?