Reputation: 587
i wont it to work until it reach a somepoint . So how can i close the webview and go to another widget after i got the request.url.startsWith('https://youtube.com/')
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebPageAuth extends StatefulWidget {
final url;
WebPageAuth(this.url);
@override
_WebPageAuthState createState() => _WebPageAuthState(this.url);
}
class _WebPageAuthState extends State<WebPageAuth> {
var _url;
final _key = UniqueKey();
_WebPageAuthState(this._url);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url,
navigationDelegate: (NavigationRequest request) {
request.url.startsWith('https://youtube.com/');
var Value = request.url ;
return NavigationDecision.navigate;
}),
),
],
),
);
}
}
Upvotes: 6
Views: 9944
Reputation: 31
You can check the URL then change the state:
navigationDelegate: (NavigationRequest request) {
if (request.url == 'http://destination.com/') {
setState(() {
_dstReached = true;
});
// do not navigate
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
}
In the build function, you can check the state and build the next widget like this:
@override
Widget build(BuildContext context) {
return Scaffold(
// display Text widget if destination was reached
// otherwise use WebView
body: _dstReached ? Text('next step') : Column(
children: [
Expanded(
child: WebView(...
Upvotes: 3