title: Flutter WebView keep logged in
body: <p>I'm trying to build an extremely simple hybrid app with flutter: it basically just connects to my website, that's it. All the functionalities I need are in the website itself.</p>
  <p>I have a login system that allows users to &quot;stay logged in&quot; even when their session ends (the website is made with Flask by the way).</p>
  <p>In my app, however, this works weirdly: sometimes it works, sometimes it doesn't. I'm thinking it could be something related to the fact that I have implemented a native back button feature (to go back to previusly visited page), but I have no idea what to do because the &quot;keep logged in&quot; feature works everywhere except for the app. (even google chrome on my phone works)</p>
  <p>Here's my app:</p>
  <pre><code>class _MyAppState extends State&lt;MyApp&gt;{
    late WebViewController wv_controller;
  
    @override
    Widget build(BuildContext context){
      return MaterialApp(
        home: WillPopScope(
          onWillPop: ()async{
            String? url = await wv_controller.currentUrl();
  
            if(url == &quot;http://*mywebsite*/&quot;){
              return true;
            } else {
              wv_controller.goBack();
              return false;
            }
          },
          child: Scaffold(
            body: Container(
              child: SafeArea(
                child: WebView(
                  javascriptMode: JavascriptMode.unrestricted,
                  initialUrl: &quot;http://*mywebsite*/&quot;,
  
                  onWebViewCreated: (WebViewController wv){
                    wv_controller = wv;
                  },
                ),
              ),
            ),
          ),
        ),
      );
    }
  }
  </code></pre>