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 - 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:

View file

@ -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 = (

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/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');
try {
final response = await http.post( final response = await http.post(
url, url,
body: json.encode(body), body: json.encode(body),
); );
// debugPrint(response.body);
if (response.statusCode == 200) { if (response.statusCode == 200) {
final responseJson = json.decode(response.body); final responseJson = json.decode(response.body);
var user = new LoginModel.fromJson(responseJson);
saveCurrentLogin(responseJson, body["email"]); saveCurrentLogin(responseJson, body["email"]);
Navigator.of(context).pushReplacementNamed('/HomePage'); Navigator.of(context).pushReplacementNamed('/HomePage');
return LoginModel.fromJson(responseJson); return LoginModel.fromJson(responseJson);
} else { } else {
// debugPrint("Invalid, either credentials are wrong or server is down");
final responseJson = json.decode(response.body); final responseJson = json.decode(response.body);
saveCurrentLogin(responseJson, body["email"]); saveCurrentLogin(responseJson, body["email"]);
_incorrectDialog(context); _incorrectDialog(context, true);
return null; return null;
} }
} catch (_) {
_incorrectDialog(context, false);
}
} }