Added message for when the server is down
This commit is contained in:
parent
9b34dd370d
commit
41bc274965
3 changed files with 24 additions and 24 deletions
|
@ -6,13 +6,13 @@ PODS:
|
||||||
- Flutter
|
- Flutter
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- Flutter (from `.symlinks/flutter/ios-profile`)
|
- Flutter (from `.symlinks/flutter/ios`)
|
||||||
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
|
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
|
||||||
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
|
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: ".symlinks/flutter/ios-profile"
|
:path: ".symlinks/flutter/ios"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
:path: ".symlinks/plugins/shared_preferences/ios"
|
:path: ".symlinks/plugins/shared_preferences/ios"
|
||||||
url_launcher:
|
url_launcher:
|
||||||
|
|
|
@ -281,7 +281,7 @@
|
||||||
);
|
);
|
||||||
inputPaths = (
|
inputPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
|
||||||
"${PODS_ROOT}/../.symlinks/flutter/ios-profile/Flutter.framework",
|
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
|
||||||
);
|
);
|
||||||
name = "[CP] Embed Pods Frameworks";
|
name = "[CP] Embed Pods Frameworks";
|
||||||
outputPaths = (
|
outputPaths = (
|
||||||
|
|
|
@ -7,14 +7,14 @@ import 'package:local_spend/common/functions/save_current_login.dart';
|
||||||
import 'package:local_spend/common/functions/show_dialog_single_button.dart';
|
import 'package:local_spend/common/functions/show_dialog_single_button.dart';
|
||||||
import 'package:local_spend/model/json/login_model.dart';
|
import 'package:local_spend/model/json/login_model.dart';
|
||||||
|
|
||||||
Future<void> _incorrectDialog(BuildContext context) async {
|
Future<void> _incorrectDialog(BuildContext context, bool isLoginWrong) async {
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("Unable to Login"),
|
title: Text("Unable to Login"),
|
||||||
content: Text("Incorrect login details. Please try again."),
|
content: Text(isLoginWrong ? "Incorrect login details. Please try again." : "The server is having issues; sorry for the inconvenience. Please try again later."),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(
|
FlatButton(
|
||||||
child: Text('OK'),
|
child: Text('OK'),
|
||||||
|
@ -40,30 +40,30 @@ Future<LoginModel> requestLoginAPI(
|
||||||
|
|
||||||
// debugPrint('$body');
|
// debugPrint('$body');
|
||||||
|
|
||||||
final response = await http.post(
|
try {
|
||||||
url,
|
final response = await http.post(
|
||||||
body: json.encode(body),
|
url,
|
||||||
);
|
body: json.encode(body),
|
||||||
|
);
|
||||||
|
|
||||||
// debugPrint(response.body);
|
if (response.statusCode == 200) {
|
||||||
|
final responseJson = json.decode(response.body);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
saveCurrentLogin(responseJson, body["email"]);
|
||||||
final responseJson = json.decode(response.body);
|
Navigator.of(context).pushReplacementNamed('/HomePage');
|
||||||
var user = new LoginModel.fromJson(responseJson);
|
|
||||||
|
|
||||||
saveCurrentLogin(responseJson, body["email"]);
|
return LoginModel.fromJson(responseJson);
|
||||||
Navigator.of(context).pushReplacementNamed('/HomePage');
|
} else {
|
||||||
|
final responseJson = json.decode(response.body);
|
||||||
|
|
||||||
return LoginModel.fromJson(responseJson);
|
saveCurrentLogin(responseJson, body["email"]);
|
||||||
} else {
|
|
||||||
// debugPrint("Invalid, either credentials are wrong or server is down");
|
|
||||||
|
|
||||||
final responseJson = json.decode(response.body);
|
_incorrectDialog(context, true);
|
||||||
|
|
||||||
saveCurrentLogin(responseJson, body["email"]);
|
return null;
|
||||||
|
}
|
||||||
_incorrectDialog(context);
|
} catch (_) {
|
||||||
|
_incorrectDialog(context, false);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue