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.