A simple demo app showing how to save images and files from Flutter and access the data from native widgets.
Flutter (save) — lib/main.dart:
await HomeWidget.saveImage(_imageKey, imageProvider);
await HomeWidget.saveWidgetData(_imageTypeKey, imageType.name);await HomeWidget.saveFile(
_fileJsonKey,
Uint8List.fromList(utf8.encode(json)),
extension: 'json',
);Android (path → file) — ImageWidgetHomeWidget.kt, FileWidgetHomeWidget.kt:
val imagePath = prefs.getString(IMAGE_KEY, null)
BitmapFactory.decodeFile(imagePath) // after `File(path).isFile` checkval jsonPath = prefs.getString(FILE_JSON_KEY, null)
File(jsonPath).readText(Charsets.UTF_8) // when path exists and is a fileiOS (path → file) — ImageWidgetHomeWidget/Widget.swift, FileWidgetHomeWidget/Widget.swift:
UserDefaults(suiteName: appGroupId)?.string(forKey: imageKey) // then UIImage(contentsOfFile:)UserDefaults(suiteName: appGroupId)?.string(forKey: fileJsonKey) // then Data(contentsOf: URL(fileURLWithPath:))