Reputation: 479
I mean when I log in, but the network to the database there is a problem, an information dialog will appear that the network has a problem. I'm confused about using else if here..
_login() async {
if (formKey.currentState.validate()) {
formKey.currentState.save();
try {
final response = await UserController.login({
"username": username,
"password": password,
});
if (response != null && response["success"]) {
Http.setAccessToken(response["token"]);
return Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MainActivity(),
));
} else {
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Information"),
content: Text("Your account is not registered!"),
actions: <Widget>[
FlatButton(
child: Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
} catch (e) {
print(e.message);
}
}
}
how do I put conditions if the network has a problem then return showDialog ??
Upvotes: 0
Views: 1885
Reputation: 1397
Check out the connectivity package from the Flutter Team. https://pub.dev/packages/connectivity
You can listen for any issues in changes to your network then show a snackbar or dialogbox if disconnected.
I hope this helps.
JC
Upvotes: 2