From 25c3f0a6c07a2c08fa3cfd4cf316d991b3da6035 Mon Sep 17 00:00:00 2001 From: ngomile Date: Sat, 26 Aug 2023 00:41:13 +0200 Subject: [PATCH] [webview_screen] Implemented tracking of url changes when user is browser in web view --- lib/screens/webview_screen.dart | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/screens/webview_screen.dart b/lib/screens/webview_screen.dart index 08fe538..2d36e16 100644 --- a/lib/screens/webview_screen.dart +++ b/lib/screens/webview_screen.dart @@ -26,31 +26,35 @@ class _WebViewScreenState extends State { late final WebViewController controller; double _progressValue = 0.0; bool _loadingArticleView = false; + late String _url; @override void initState() { + _url = widget.url; + controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) - ..loadRequest(Uri.parse(widget.url)) + ..loadRequest(Uri.parse(_url)) ..setNavigationDelegate( - NavigationDelegate( - onProgress: (progress) { - setState(() { - _progressValue = progress / 100; - }); - }, - onPageStarted: (_) { - setState(() { - _progressValue = 0.0; - }); - }, - onPageFinished: (_) { - setState(() { - _progressValue = 1.0; - }); - }, - ), + NavigationDelegate(onProgress: (progress) { + setState(() { + _progressValue = progress / 100; + }); + }, onPageStarted: (_) { + setState(() { + _progressValue = 0.0; + }); + }, onPageFinished: (_) { + setState(() { + _progressValue = 1.0; + }); + }, onUrlChange: (UrlChange urlChange) { + setState(() { + _url = urlChange.url ?? ''; + }); + }), ); + super.initState(); } @@ -67,7 +71,7 @@ class _WebViewScreenState extends State { children: [ Text(widget.title), Text( - widget.url, + _url, style: Theme.of(context).textTheme.labelLarge, overflow: TextOverflow.fade, ),