Skip to content

Commit

Permalink
[webview_screen] Implemented tracking of url changes when user is bro…
Browse files Browse the repository at this point in the history
…wser in web view
  • Loading branch information
ngomile committed Aug 25, 2023
1 parent 87d7602 commit 25c3f0a
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions lib/screens/webview_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,35 @@ class _WebViewScreenState extends State<WebViewScreen> {
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();
}

Expand All @@ -67,7 +71,7 @@ class _WebViewScreenState extends State<WebViewScreen> {
children: [
Text(widget.title),
Text(
widget.url,
_url,
style: Theme.of(context).textTheme.labelLarge,
overflow: TextOverflow.fade,
),
Expand Down

0 comments on commit 25c3f0a

Please sign in to comment.