【问题标题】:Flutter Webview onStateChanged is not getting triggeredFlutter Webview onStateChanged 没有被触发
【发布时间】:2020-06-25 20:14:25
【问题描述】:

我有一个 stless 小部件,我可以在其中打开一个 web 视图来执行 oAuth。我希望能够跟踪用户何时到达某个页面并关闭 webview。

目前连打印语句都没有被执行!此外,我注意到在 StreamSubsctiption 部分它说“未使用字段'_onWebviewStateChange'的值。”

我做错了什么?

我的代码:

class RedditAuth extends StatefulWidget {
  static const String id = 'redditAuth';

  @override
  _RedditAuthState createState() => _RedditAuthState();
}

class _RedditAuthState extends State<RedditAuth> {
  // Initialise the RedditAuthClass and the FlutterWebviewPlugin
  RedditAuthClass authorizeReddit = RedditAuthClass();
  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();

  // Subscribe to the WebViewStateChanged
  StreamSubscription<WebViewStateChanged> _onWebviewStateChange;
  //
  @override
  void intiState() {
    super.initState();
    _onWebviewStateChange = flutterWebviewPlugin.onStateChanged.listen(
      (WebViewStateChanged state) {
        print('State has changed: ${state.url}');
        if (state.url == 'https://www.google.com') {
          flutterWebviewPlugin.hide();
        }
      },
    );
  }

//  @override
  //Dispose any stream subs

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('data'),
      ),
      body: SafeArea(
        child: WebviewScaffold(
          url: authorizeReddit.auth(),
          hidden: true,
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter webview stream


    【解决方案1】:

    当我更改这部分代码时,它开始工作。现在我需要弄清楚原因:

    最终的flutterWebviewPlugin = new FlutterWebviewPlugin();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 2017-11-22
      • 2012-06-03
      • 2019-11-07
      • 2018-09-01
      • 2018-12-03
      • 2021-04-23
      相关资源
      最近更新 更多