flutter_inappwebview
flutter_inappwebview copied to clipboard
sending big file or file path to js webview can access.
Environment
Flutter version: 3.19.16 Plugin version: 5.8.0 Android version: 31+ iOS version: 13+
Description
When get file path from dart code how to send to webview js
by now I encode to base64 and send to js via
Codec<String, String> _stringToBase64 = utf8.fuse(base64);
_intentSub = ReceiveSharingIntent.getMediaStream().listen((value) async {
for (var c in value) {
if (c.type == SharedMediaType.image) {
ShareModel m = ShareModel(
mimeType: c.mimeType,
type: c.type.name,
message: base64Encode(await File(c.path).readAsBytes()));
Utils.g_sharedFiles.add(m);
}
if (c.type == SharedMediaType.video) {
ShareModel m = ShareModel(
mimeType: c.mimeType,
type: c.type.name,
message: base64Encode(await File(c.path).readAsBytes()));
Utils.g_sharedFiles.add(m);
}
}
var jsonString =
jsonEncode(Utils.g_sharedFiles.map((f) => f.toMap()).toList());
webView.webViewController!.evaluateJavascript(source: """
app.flutter_share_stream_event('${_stringToBase64.encode(jsonString)}')
""");
}
is there another best practice. thank you.
What you'd like to happen: there some function to send file from dart to js blob or File type code