Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] Fix the issue that webview cannot load assets html and local html #2583

Closed
wants to merge 8 commits into from

Conversation

asjqkkkk
Copy link

@asjqkkkk asjqkkkk commented Mar 6, 2020

Fix flutter/flutter#27086

Now, flutter webview can load html file in two ways:

Assetfiles

    WebView(
      onWebViewCreated: (WebViewController controller) {
        final url = 'assets/index.html';
        controller.loadAssetHtmlFile(url);
      },
      javascriptMode: JavascriptMode.unrestricted,
    );

Localfiles

    WebView(
      onWebViewCreated: (WebViewController controller) {
        controller.loadLocalHtmlFile(filePath)
      },
      javascriptMode: JavascriptMode.unrestricted,
    );

  Future<void> downloadFile(String url) async {
    Dio dio = Dio();
    String path = (await getApplicationDocumentsDirectory()).path;
    String fileName=url.substring(url.lastIndexOf("/")+1);
    await Dio().download(url, '$path/$fileName',onReceiveProgress: (rec,total){
      progress = ((rec/total) * 100).floor();
      if(progress >= 100){
        filePath= '$path/$fileName';
      }
      setState(() {});
    });
  }

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@asjqkkkk
Copy link
Author

asjqkkkk commented Mar 6, 2020

I signed it!

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Mar 6, 2020
@asjqkkkk asjqkkkk changed the title [webview_plugin] Fix the issue that webview cannot load assets html and local html [webview_flutter] Fix the issue that webview cannot load assets html and local html Mar 6, 2020
@miyakeryo
Copy link
Contributor

Could you support initialUrl? Because a black background page flickers for a moment.

@asjqkkkk
Copy link
Author

Could you support initialUrl? Because a black background page flickers for a moment.

support initialUrl will bring some broken changes, this is not good for maintenance and expansion, so I didn't do that

maybe you can use some other way to load webview?

  String _urlPath;

  @override
  void initState() {
    initialUrlDynamic();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: _urlPath == null ? buildLoadingWidget(): buildWebView(),
    );
  }

@miyakeryo
Copy link
Contributor

@asjqkkkk
Thanks for your suggestion. I solved this problem by using about:blank

@SetNameHere
Copy link

Hi,
does anyone know when this feature will be available?
It seems to be a great solution for one of my biggest problems.

Thanks for all your work!

@TheOneWithTheBraid
Copy link
Contributor

Does anyone know if this will be merged in further releases?

@eric8words
Copy link

Any ETA for the merged release ?

@cyanglaz cyanglaz added this to To be reviewed in Plugin PR Triage via automation Aug 13, 2020
@cyanglaz
Copy link
Contributor

cc @bparrishMines

@Wian-TMC
Copy link

Possible ETA?

@asjqkkkk asjqkkkk closed this Oct 15, 2020
@Wian-TMC
Copy link

Wian-TMC commented Dec 3, 2020

The PR Triage has last been updated on 13 August. Is there a more up to date indication when this will be available on the master branch?

@jamesdixon
Copy link

@asjqkkkk why did you end up closing this?

@asjqkkkk
Copy link
Author

@asjqkkkk why did you end up closing this?

My branch was not updated for too many days, so I think there should be another fresh pr to fix this issue

@Wian-TMC
Copy link

Wian-TMC commented Dec 16, 2020

@asjqkkkk The master branch has fixed major issues especially regarding the keyboard and is now out of the developers preview. While we wait for the PR, Is it maybe possible for you to create a new temporary fork from the latest master branch and re-add your asset loading implementation? This would be of great help

@DineshKachhot
Copy link

Local html file is loading but local assts like image and css are still not loading in Flutter 2.2 stable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
No open projects
Plugin PR Triage
  
To be reviewed