diff --git a/lib/util/dr_app_toast_msg.dart b/lib/util/dr_app_toast_msg.dart new file mode 100644 index 00000000..e0342106 --- /dev/null +++ b/lib/util/dr_app_toast_msg.dart @@ -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(); + } +} \ No newline at end of file diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 326e2b3c..abc969e7 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -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 { 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 { 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 { 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 { 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 { }); } 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); + } } diff --git a/pubspec.lock b/pubspec.lock index a1adef56..8ae7ebe2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index b6ebd663..f7855a79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.