Added message for when the server is down

This commit is contained in:
Felix 2019-08-16 14:21:21 +01:00
parent 9b34dd370d
commit 41bc274965
3 changed files with 24 additions and 24 deletions

View File

@ -6,13 +6,13 @@ PODS:
- Flutter
DEPENDENCIES:
- Flutter (from `.symlinks/flutter/ios-profile`)
- Flutter (from `.symlinks/flutter/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
EXTERNAL SOURCES:
Flutter:
:path: ".symlinks/flutter/ios-profile"
:path: ".symlinks/flutter/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
url_launcher:

View File

@ -281,7 +281,7 @@
);
inputPaths = (
"${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";
outputPaths = (

View File

@ -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/model/json/login_model.dart';
Future<void> _incorrectDialog(BuildContext context) async {
Future<void> _incorrectDialog(BuildContext context, bool isLoginWrong) async {
return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
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>[
FlatButton(
child: Text('OK'),
@ -40,30 +40,30 @@ Future<LoginModel> requestLoginAPI(
// debugPrint('$body');
final response = await http.post(
url,
body: json.encode(body),
);
try {
final response = await http.post(
url,
body: json.encode(body),
);
// debugPrint(response.body);
if (response.statusCode == 200) {
final responseJson = json.decode(response.body);
if (response.statusCode == 200) {
final responseJson = json.decode(response.body);
var user = new LoginModel.fromJson(responseJson);
saveCurrentLogin(responseJson, body["email"]);
Navigator.of(context).pushReplacementNamed('/HomePage');
saveCurrentLogin(responseJson, body["email"]);
Navigator.of(context).pushReplacementNamed('/HomePage');
return LoginModel.fromJson(responseJson);
} else {
final responseJson = json.decode(response.body);
return LoginModel.fromJson(responseJson);
} else {
// debugPrint("Invalid, either credentials are wrong or server is down");
saveCurrentLogin(responseJson, body["email"]);
final responseJson = json.decode(response.body);
_incorrectDialog(context, true);
saveCurrentLogin(responseJson, body["email"]);
_incorrectDialog(context);
return null;
return null;
}
} catch (_) {
_incorrectDialog(context, false);
}
}