| @@ -0,0 +1,26 @@ | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:get/get.dart'; | |||
| class Utils { | |||
| static void showSnackBarSuccess({String message}) { | |||
| if (Get.isSnackbarOpen) Get.back(); | |||
| Get.snackbar(null, message, | |||
| icon: Icon( | |||
| Icons.done, | |||
| color: Colors.white, | |||
| ), | |||
| snackPosition: SnackPosition.BOTTOM, | |||
| backgroundColor: Colors.green); | |||
| } | |||
| static void showSnackBarError({String message}) { | |||
| if (Get.isSnackbarOpen) Get.back(); | |||
| Get.snackbar(null, message, | |||
| icon: Icon( | |||
| Icons.error, | |||
| color: Colors.white, | |||
| ), | |||
| snackPosition: SnackPosition.BOTTOM, | |||
| backgroundColor: Colors.red); | |||
| } | |||
| } | |||
| @@ -14,11 +14,9 @@ import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:farm_tpf/utils/const_style.dart'; | |||
| import 'package:farm_tpf/utils/pref.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'package:intl/intl.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| @@ -14,11 +14,9 @@ import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:farm_tpf/utils/const_style.dart'; | |||
| import 'package:farm_tpf/utils/pref.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'package:intl/intl.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| @@ -1,10 +1,10 @@ | |||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||
| import 'package:farm_tpf/utils/const_color.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| class ForgotPasswordScreen extends StatefulWidget { | |||
| @@ -19,12 +19,10 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> { | |||
| bool _autoValidate = false; | |||
| TextEditingController _emailController = TextEditingController(); | |||
| String _email = ""; | |||
| FlutterToast flutterToast; | |||
| @override | |||
| void initState() { | |||
| super.initState(); | |||
| flutterToast = FlutterToast(context); | |||
| } | |||
| _validateInputs() async { | |||
| @@ -33,22 +31,11 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> { | |||
| LoadingDialog.showLoadingDialog(context); | |||
| _userRepository.forgotPassword(_email).then((value) { | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| flutterToast.showToast( | |||
| child: WidgetToast(message: "Gửi email thành công.")); | |||
| Utils.showSnackBarSuccess(message: "Gửi email thành công"); | |||
| Navigator.pop(context); | |||
| }).catchError((error) { | |||
| _scaffoldKey.currentState.showSnackBar(SnackBar( | |||
| content: Row( | |||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |||
| children: <Widget>[ | |||
| Text('Email không tồn tại.'), | |||
| Icon(Icons.error), | |||
| ], | |||
| ), | |||
| backgroundColor: Colors.red, | |||
| duration: Duration(seconds: 3), | |||
| )); | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| Utils.showSnackBarError(message: 'Email không tồn tại'); | |||
| }); | |||
| } else { | |||
| _autoValidate = true; | |||
| @@ -4,11 +4,11 @@ import 'package:farm_tpf/data/repository/repository.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||
| import 'package:farm_tpf/presentation/screens/plot_detail/bloc_plot_information.dart'; | |||
| import 'package:farm_tpf/utils/const_color.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| import 'package:farm_tpf/utils/formatter.dart'; | |||
| @@ -37,7 +37,6 @@ class _PlotInformationScreenState extends State<PlotInformationScreen> { | |||
| TextEditingController _areaController = TextEditingController(); | |||
| TextEditingController _descriptionController = TextEditingController(); | |||
| FlutterToast flutterToast; | |||
| bool _autoValidate = false; | |||
| TbCropDTO _crop = TbCropDTO(); | |||
| final controller = Get.put(DescriptionChangeControler()); | |||
| @@ -46,7 +45,6 @@ class _PlotInformationScreenState extends State<PlotInformationScreen> { | |||
| @override | |||
| void initState() { | |||
| super.initState(); | |||
| flutterToast = FlutterToast(context); | |||
| getPlotInfoBloc.getPlotInfo(widget.cropId, (data) { | |||
| var result = data as CropPlot; | |||
| _crop = result.tbCropDTO; | |||
| @@ -90,22 +88,11 @@ class _PlotInformationScreenState extends State<PlotInformationScreen> { | |||
| LoadingDialog.showLoadingDialog(context); | |||
| _repository.updatePlot(_crop).then((value) { | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| flutterToast.showToast( | |||
| child: WidgetToast(message: label_update_success)); | |||
| Utils.showSnackBarSuccess(message: label_update_success); | |||
| controller.initValue(); | |||
| }).catchError((error) { | |||
| _scaffoldKey.currentState.showSnackBar(SnackBar( | |||
| content: Row( | |||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |||
| children: <Widget>[ | |||
| Flexible(child: Text(AppException.handleError(error))), | |||
| Icon(Icons.error), | |||
| ], | |||
| ), | |||
| backgroundColor: Colors.red, | |||
| duration: Duration(seconds: 3), | |||
| )); | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| Utils.showSnackBarError(message: AppException.handleError(error)); | |||
| }); | |||
| } else { | |||
| _autoValidate = true; | |||
| @@ -3,10 +3,10 @@ import 'package:farm_tpf/data/api/app_exception.dart'; | |||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||
| import 'package:farm_tpf/utils/const_color.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| class ChangePasswordScreen extends StatefulWidget { | |||
| @@ -19,7 +19,6 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> { | |||
| final _repository = UserRepository(); | |||
| GlobalKey<FormState> _formKey = GlobalKey(); | |||
| bool _autoValidate = false; | |||
| FlutterToast flutterToast; | |||
| Password _password = Password(); | |||
| TextEditingController _currentPasswordController = TextEditingController(); | |||
| @@ -29,7 +28,6 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> { | |||
| @override | |||
| void initState() { | |||
| super.initState(); | |||
| flutterToast = FlutterToast(context); | |||
| } | |||
| _validateInputs() async { | |||
| @@ -38,26 +36,13 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> { | |||
| LoadingDialog.showLoadingDialog(context); | |||
| _repository.changePassword(_password).then((value) { | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| flutterToast.showToast( | |||
| child: WidgetToast(message: "Cập nhật thành công")); | |||
| Navigator.pop(context); | |||
| Utils.showSnackBarSuccess(message: "Cập nhật thành công"); | |||
| }).catchError((onError) { | |||
| var errorMessage = AppException.handleError(onError, | |||
| customMessageError: "Sai mật khẩu hiện tại"); | |||
| _scaffoldKey.currentState.showSnackBar(SnackBar( | |||
| content: Row( | |||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |||
| children: <Widget>[ | |||
| Flexible( | |||
| child: Text(errorMessage), | |||
| ), | |||
| Icon(Icons.error), | |||
| ], | |||
| ), | |||
| backgroundColor: Colors.red, | |||
| duration: Duration(seconds: 3), | |||
| )); | |||
| LoadingDialog.hideLoadingDialog(context); | |||
| Utils.showSnackBarError( | |||
| message: AppException.handleError(onError, | |||
| customMessageError: "Sai mật khẩu hiện tại")); | |||
| }); | |||
| } else { | |||
| _autoValidate = true; | |||
| @@ -3,6 +3,7 @@ import 'package:farm_tpf/custom_model/account.dart'; | |||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_supply.dart'; | |||
| import 'package:farm_tpf/presentation/screens/location_unit/sc_location.dart'; | |||
| import 'package:farm_tpf/presentation/screens/profile/controller/check_change_another_dropdown.dart'; | |||
| @@ -13,7 +14,6 @@ import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:farm_tpf/utils/const_style.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:fluttertoast/fluttertoast.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | |||
| import 'package:package_info/package_info.dart'; | |||
| @@ -34,7 +34,6 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> { | |||
| final _repository = UserRepository(); | |||
| GlobalKey<FormState> _formKey = GlobalKey(); | |||
| bool _autoValidate = false; | |||
| FlutterToast flutterToast; | |||
| Account _account = Account(); | |||
| TextEditingController _userNameController = TextEditingController(); | |||
| @@ -60,7 +59,6 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> { | |||
| super.initState(); | |||
| checkChangeLocation.initValue(); | |||
| _initPackageInfo(); | |||
| flutterToast = FlutterToast(context); | |||
| getAccountBloc.getAccount((data) { | |||
| _account = data; | |||
| _userNameController.text = _account.login; | |||
| @@ -76,7 +74,7 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> { | |||
| checkChangeLocation.changeWardByIdAndName( | |||
| _account.wardId, _account.wardName); | |||
| }, (err) { | |||
| flutterToast.showToast(child: WidgetToast(message: "Lỗi tải dữ liệu")); | |||
| Utils.showSnackBarError(message: "Lỗi tải dữ liệu"); | |||
| }); | |||
| } | |||
| @@ -90,29 +88,9 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> { | |||
| LoadingDialog.showLoadingDialog(_scaffoldKey.currentContext); | |||
| _repository.updateProfile(_account).then((value) { | |||
| LoadingDialog.hideLoadingDialog(_scaffoldKey.currentContext); | |||
| _scaffoldKey.currentState.showSnackBar(SnackBar( | |||
| content: Row( | |||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |||
| children: <Widget>[ | |||
| Text('Cập nhật thành công.'), | |||
| Icon(Icons.done), | |||
| ], | |||
| ), | |||
| backgroundColor: Colors.green, | |||
| duration: Duration(seconds: 3), | |||
| )); | |||
| Utils.showSnackBarSuccess(message: 'Cập nhật thành công.'); | |||
| }).catchError((onError) { | |||
| _scaffoldKey.currentState.showSnackBar(SnackBar( | |||
| content: Row( | |||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |||
| children: <Widget>[ | |||
| Text('Cập nhật không thành công.'), | |||
| Icon(Icons.error), | |||
| ], | |||
| ), | |||
| backgroundColor: Colors.red, | |||
| duration: Duration(seconds: 3), | |||
| )); | |||
| Utils.showSnackBarError(message: 'Cập nhật không thành công.'); | |||
| LoadingDialog.hideLoadingDialog(_scaffoldKey.currentContext); | |||
| print("error"); | |||
| }); | |||
| @@ -345,13 +345,6 @@ packages: | |||
| description: flutter | |||
| source: sdk | |||
| version: "0.0.0" | |||
| fluttertoast: | |||
| dependency: "direct main" | |||
| description: | |||
| name: fluttertoast | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "6.0.1" | |||
| font_awesome_flutter: | |||
| dependency: "direct main" | |||
| description: | |||
| @@ -23,7 +23,6 @@ dependencies: | |||
| dio_http_cache: ^0.2.9 | |||
| formz: ^0.3.0 | |||
| keyboard_dismisser: ^1.0.2 | |||
| fluttertoast: ^6.0.1 | |||
| pattern_formatter: ^1.0.2 | |||
| rxdart: ^0.23.0 | |||
| barcode_scan: ^3.0.1 | |||