Flutter WebView keep logged in

Viewed 1180

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.

I have a login system that allows users to "stay logged in" even when their session ends (the website is made with Flask by the way).

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 "keep logged in" feature works everywhere except for the app. (even google chrome on my phone works)

Here's my app:

class _MyAppState extends State<MyApp>{
  late WebViewController wv_controller;

  @override
  Widget build(BuildContext context){
    return MaterialApp(
      home: WillPopScope(
        onWillPop: ()async{
          String? url = await wv_controller.currentUrl();

          if(url == "http://*mywebsite*/"){
            return true;
          } else {
            wv_controller.goBack();
            return false;
          }
        },
        child: Scaffold(
          body: Container(
            child: SafeArea(
              child: WebView(
                javascriptMode: JavascriptMode.unrestricted,
                initialUrl: "http://*mywebsite*/",

                onWebViewCreated: (WebViewController wv){
                  wv_controller = wv;
                },
              ),
            ),
          ),
        ),
      ),
    );
  }
}
0 Answers
Related