4

我正在使用 flutter_webview_plugin 包来显示网页。在网页上,我们有一个下载文件的功能。下载文件的逻辑类似于下面的代码

 filename = "my-file.txt"
 content = 'any string generated by django'
 response = HttpResponse(content, content_type='text/plain')
 response['Content-Disposition'] = 'attachment;filename={0}'.format(filename) 
 print(response)
 return response

当它在浏览器中直接调用时它工作正常,但在 Flutter Webview 中没有任何效果。有什么需要手动处理的吗?即使我愿意更改包。我也尝试了flutter_inappwebview,但没有区别。我不想启动任何浏览器的 URL,我只想直接从应用程序下载。可以这样做吗?

4

1 回答 1

0

我建议你试试这个包,flutter_inappwebview,以获得更好的性能:

  final GlobalKey webViewKey = GlobalKey();

  InAppWebViewController? webViewController;
  InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
      crossPlatform: InAppWebViewOptions(
        useShouldOverrideUrlLoading: true,
        mediaPlaybackRequiresUserGesture: false,
      ),
      android: AndroidInAppWebViewOptions(
        useHybridComposition: true,
      ),
      ios: IOSInAppWebViewOptions(
        allowsInlineMediaPlayback: true,
      ));

...

                      InAppWebView(
                        key: webViewKey,
                        initialUrlRequest:
                        URLRequest(url: Uri.parse("https://inappwebview.dev/")),
                        initialOptions: options,
于 2021-08-18T05:57:32.510 回答