如何关闭webview抖动

Abd*_*rim 6 flutter

我不会让它工作,直到它达到某个点。那么,在收到 request.url.startsWith('https://youtube.com/') 后,如何关闭 webview 并转到另一个小部件

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;
            }),
      ),
    ],
  ),
);
}
}
Run Code Online (Sandbox Code Playgroud)

小智 3

您可以检查 URL 然后更改状态:

navigationDelegate: (NavigationRequest request) {
    if (request.url == 'http://destination.com/') {
       setState(() {
           _dstReached = true;           
       });
       // do not navigate
       return NavigationDecision.prevent;
    }

    return NavigationDecision.navigate;
}
Run Code Online (Sandbox Code Playgroud)

在构建函数中,您可以检查状态并构建下一个小部件,如下所示:

@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(...
Run Code Online (Sandbox Code Playgroud)