[9-10] H5 actual mixing custom WebView-based mixed development -3 achieve H5

Good package WebView, following to use it. Nav Click inside each icon will jump to H5 page.
Jump need to use Navigator to push a page. Which is then used MaterialPageRoute,

introducing the widget WebVIew


Run the test

Click



Click the button to the left to return.

Click Back, and did not return to our home page, but open another page H5


This page is H5 Ctrip home

how to circumvent this problem? It took both need to expand our WebView and be a mix between H5.
In our webView page loads the specified url when. native would do something to avoid it does not load the url.
When the url changes in OnStateChanged receive monitoring.

If the judgment is written in a jump or other H5 home page, do not let him jump, but return to our home page.

At the top configure some white list. It contains a number of domain name Ctrip may arise.

It provides a method to determine

In a method of determining dart which object does not exist in memory. + Point question mark:? .
When the presence of our url, otherwise just call endsWith taking the false

case if it is false or does not exist, directly to false








return to the previous page by flutter inside the pop method.


Plus a state is returned. The default is no return

after return to the home, it is set to true

so that Navigator does not return repeated.

Run the test

Click to return and did not return to our home page.

Error code is






returned successfully

to sum up

如果禁制返回,就是不允许webview打开其他页面,只允许打开它自身。

结束

 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/12207995.html