0

I'm making a mobile app that should login in a Website. I'm using this function to login and it is working. Values user and pass are taken from a TextField.


late WebViewController controller;
String user;
String pass;

Future<void> login() async {
    await controller.loadUrl(urlToLogin);
    await Future.delayed(Duration(seconds: 1));
    final user = await storage.read(key: 'user');
    final pass = await storage.read(key: 'pass');
    await controller
        .runJavascript("document.getElementById('j_username').value='$user'");
    await controller
        .runJavascript("document.getElementById('j_password').value='$pass'");
    await Future.delayed(Duration(seconds: 1));
    await controller.runJavascript('document.forms[0].submit()');
  }


The problem is that sometimes could not be data connection, like I'm walking inside a tunnel. So if a user faces this issue I'd like to popup an alert that tells user to try again later.

Another task is that I want to know if the login succeeded because maybe user, by mistake, typed a wrong user or pass inside the TextField.

In other words, is that the possibility to know, using controller.runJavaScript if the login succeeded?

Thanks in advance L.

Soasa
  • 65
  • 8
  • This may help you https://stackoverflow.com/questions/53689662/flutter-webview-two-way-communication-with-javascript and for the internet problem you can use https://pub.dev/packages/connectivity_plus to check the current connectivity state – Ozan Taskiran Sep 16 '22 at 14:11

0 Answers0