add DrAppToastMsg and handle error in the login page

merge-requests/1/merge
Elham Rababah 5 years ago
parent f3a96adf3c
commit c0168cb8fb

@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import 'package:flutter_flexible_toast/flutter_flexible_toast.dart';
mixin DrAppToastMsg {
void showLongToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_LONG,
);
}
void showSuccesToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_SHORT,
backgroundColor: Colors.green,
icon: ICON.SUCCESS,
fontSize: 16,
imageSize: 35,
textColor: Colors.white);
}
void showErrorToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_SHORT,
backgroundColor: Colors.red,
icon: ICON.CLOSE,
fontSize: 16,
imageSize: 35,
textColor: Colors.white);
}
void showShortToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_SHORT,
icon: ICON.INFO,
timeInSeconds: 1);
}
void showTopShortToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_SHORT,
toastGravity: ToastGravity.TOP,
icon: ICON.WARNING,
timeInSeconds: 1);
}
void showCenterShortToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_SHORT,
toastGravity: ToastGravity.CENTER,
icon: ICON.WARNING,
timeInSeconds: 1);
}
void showCenterShortLoadingToast(msg) {
FlutterFlexibleToast.showToast(
message: msg,
toastLength: Toast.LENGTH_LONG,
toastGravity: ToastGravity.BOTTOM,
icon: ICON.LOADING,
radius: 20,
elevation: 10,
textColor: Colors.white,
backgroundColor: Colors.black,
timeInSeconds: 2);
}
void cancelToast(msg) {
FlutterFlexibleToast.cancel();
}
}

@ -1,4 +1,5 @@
import 'package:doctor_app_flutter/providers/projects_provider.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
@ -11,7 +12,7 @@ import '../../models/user_model.dart';
import '../../providers/auth_provider.dart';
import '../../routes.dart';
class LoginForm extends StatefulWidget {
class LoginForm extends StatefulWidget with DrAppToastMsg {
LoginForm({
Key key,
}) : super(key: key);
@ -63,6 +64,7 @@ class _LoginFormState extends State<LoginForm> {
height: 20,
),
TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Image.asset('assets/images/user_id_icon.png'),
hintText: 'Enter ID',
@ -244,15 +246,15 @@ class _LoginFormState extends State<LoginForm> {
authProv.login(userInfo).then((res) {
if (res['MessageStatus'] == 1) {
insertDeviceImei(res, authProv);
// call insert imei
// save imei on shared preferance
// handel errors
} else {
// handel error
// widget.showCenterShortLoadingToast("watting");
showLoginError(res['ErrorEndUserMessage']);
}
Navigator.of(context).pushNamed(HOME);
// Navigator.of(context).pushNamed(HOME);
}).catchError((err) {
print('$err');
showLoginError();
});
}
@ -276,12 +278,15 @@ class _LoginFormState extends State<LoginForm> {
authProv.insertDeviceImei(imeiInfo).then((res) {
if (res['MessageStatus'] == 1) {
setSharedPref('platformImei', _platformImei);
Navigator.of(context).pushNamed(HOME);
// save imei on shared preferance
} else {
// handel error
showLoginError(res['ErrorEndUserMessage']);
}
}).catchError((err) {
print(err);
showLoginError();
});
}
}
@ -315,7 +320,6 @@ class _LoginFormState extends State<LoginForm> {
final SharedPreferences prefs = await _prefs;
prefs.setString(key, value).then((bool success) {
print('EEEEEEEEEEee');
print(prefs.getString('platformImei'));
return value;
});
@ -330,9 +334,20 @@ class _LoginFormState extends State<LoginForm> {
});
} else {
// handel error
}
}).catchError((err) {
print(err);
});
}
showLoginError([msg = null]) {
String localMsg = 'Something wrong happened, please contact the admin';
if (msg != null) {
localMsg = msg.toString();
}
widget.showErrorToast(localMsg);
}
}

@ -202,6 +202,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
flutter_flexible_toast:
dependency: "direct main"
description:
name: flutter_flexible_toast
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
flutter_test:
dependency: "direct dev"
description: flutter

@ -27,6 +27,8 @@ dependencies:
i18n: any
shared_preferences: ^0.5.6+3
imei_plugin: ^1.1.6
flutter_flexible_toast: ^0.1.4
# The following adds the Cupertino Icons font to your application.

Loading…
Cancel
Save