英文:
WebView loadFile not working on Android, But works on IOS
问题
以下是您提供的代码的翻译部分:
加载进度已经达到100%,但没有显示文件。
尝试更改路径
尝试从西里尔字母转换为拉丁字母
尝试externalStorageDir
@override
void initState() {
controller
..setJavaScriptMode(JavaScriptMode.unrestricted)
..enableZoom(true)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
printMessage("viewer progress : $progress");
},
onPageStarted: (String url) {},
onPageFinished: (String url) {},
onWebResourceError: (WebResourceError error) {
setState(() {
canRenderFile = false;
});
printMessage("error viewer ${error.description}");
},
),
);
super.initState();
}
@override
Widget build(BuildContext context) {
printMessage(widget._path ?? "");
if (canRenderFile) {
controller.loadFile(widget._path ?? "");
}
if (canRenderFile == true) {
return WebViewWidget(controller: controller);
} else {
return DownloadFileView(
fileName: widget.file?.name ?? "",
fileSize: widget.file?.fileSize.toUiSize().toString() ?? "",
onAction: () {
widget.onDownload?.call();
},
);
}
}
}
这是我的代码
canRenderFile默认为true
请注意,代码中的"
被翻译成了正常的双引号 "
.
英文:
Load progress is equal 100 but not showing file.
Tried to change path
Tried change from Cyrillic to Latin
Tried externalStorageDir
@override
void initState() {
controller
..setJavaScriptMode(JavaScriptMode.unrestricted)
..enableZoom(true)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
printMessage("viewer progress : $progress");
},
onPageStarted: (String url) {},
onPageFinished: (String url) {},
onWebResourceError: (WebResourceError error) {
setState(() {
canRenderFile = false;
});
printMessage("error viewer ${error.description}");
},
),
);
super.initState();
}
@override
Widget build(BuildContext context) {
printMessage(widget._path ?? "");
if (canRenderFile) {
controller.loadFile(widget._path ?? "");
}
if (canRenderFile == true) {
return WebViewWidget(controller: controller);
} else {
return DownloadFileView(
fileName: widget.file?.name ?? "",
fileSize: widget.file?.fileSize.toUiSize().toString() ?? "",
onAction: () {
widget.onDownload?.call();
},
);
}
}
}
This is my code
canRenderFile is default = true
答案1
得分: 1
在Android上,如果您尝试使用WebView来显示任何文件(例如PDF),那么它将不显示任何内容。进度将显示100%,不会出现错误,但内容不会显示。因此,在这里,您将不得不使用某个库来预览文件,或者只需编写一些代码来显示系统弹出窗口,显示查看文件的选项。
英文:
On android , if you will try to use webview to show any file (for ex PDF) then it will not show anything .. progress will show 100% and no error will be there but content will not show . So here you will have to use either some library to preview file or just do some code to show system popup that shows options to view that file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论