简体   繁体   English

颤抖的webview恢复状态

[英]Flutter webview resuming the state

Hi I have one button in my home screen when clicking that button..it will open a new page with webview widget.(ex.webview widget initial URL is google,so it will open google.com).After that I am doing some interaction with that webpage,then Clicking back button will take me to home screen.If I click the button now,I want to open webview with resume interaction.(ex. I click on that button and it takes me google then I search for 'computer' in Google and it shows me the results.now clicking back button will take me home screen.again now I click on home screen button it will have to open webview with computer searched results).any idea?.......oh. 嗨,我点击该按钮时,我的主屏幕中有一个按钮..这将打开一个带有webview小部件的新页面。(例如,浏览小部件的初始URL是google,所以它将打开google.com)。之后我正在做一些与该网页的互动,然后点击后退按钮将我带到主屏幕。如果我现在点击按钮,我想打开webview与恢复互动。(例如,我点击该按钮,它需要我google然后我搜索'计算机'在谷歌,它向我显示结果。现在点击后退按钮将带我回家屏幕。现在我点击主屏幕按钮它将打开webview与计算机搜索结果)。任何想法?...... 。哦。 And I found out this one method OnUrlChanged.listen()...but I don't know where to put it exactly?? 我发现了这个方法OnUrlChanged.listen()...但我不知道在哪里把它完全?

Declaring variables 声明变量

final flutterWebviewPlugin = FlutterWebviewPlugin();
String oldUrl;

... ...

@override
Widget build(BuildContext context) {

flutterWebviewPlugin.onUrlChanged.listen((String url) {
oldUrl = url;} //You might have to use async here
.....

... ...

In Your WebView Class 在您的WebView类中

return SafeArea(
          child: WebviewScaffold(
            url: oldURl==null? "www.google.com" : oldUrl ))

I assume you'll have a MaterialPageRoute to navigate to Webview from your button. 我假设你将有一个MaterialPageRoute从你的按钮导航到Webview You can create the class with a parameter for url, and pass oldUrl or "google.com" as a parameter in it accordingly. 您可以使用url参数创建class ,并相应地将oldUrl或“google.com”作为参数传递oldUrl它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM