Flutter Webview onStateChanged 没有被触发

Flutter Webview onStateChanged is not getting triggered

我有一个 stless 小部件,我可以在其中打开一个 webview 来执行 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,
        ),
      ),
    );
  }
}

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

final flutterWebviewPlugin = new FlutterWebviewPlugin();