| @@ -1 +1 @@ | |||
| 440505e9ea1eee7043d2cbfeb318f6bc | |||
| 5729eb498eaeb9c64784fcfc80bbb33b | |||
| @@ -0,0 +1,37 @@ | |||
| import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:farm_tpf/utils/validators.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:flutter/services.dart'; | |||
| import 'package:intl/intl.dart'; | |||
| import 'package:pattern_formatter/pattern_formatter.dart'; | |||
| class WidgetTextFormFieldNumber extends StatelessWidget { | |||
| final TextEditingController textController; | |||
| final void Function(String) onSaved; | |||
| final void Function(String) validator; | |||
| final String hintValue; | |||
| WidgetTextFormFieldNumber( | |||
| {@required this.textController, | |||
| @required this.onSaved, | |||
| @required this.hintValue, | |||
| this.validator}); | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return TextFormField( | |||
| keyboardType: TextInputType.numberWithOptions(decimal: true), | |||
| inputFormatters: [ | |||
| FilteringTextInputFormatter.allow(ConstCommon.regExpDecimal), | |||
| ThousandsFormatter( | |||
| formatter: NumberFormat("#,###.####", "es"), allowFraction: true), | |||
| ], | |||
| decoration: InputDecoration(labelText: hintValue), | |||
| validator: validator ?? | |||
| (String value) { | |||
| return Validators.validNumberOrEmpty(value, label_invalid_number); | |||
| }, | |||
| controller: textController, | |||
| onSaved: onSaved, | |||
| ); | |||
| } | |||
| } | |||
| @@ -7,6 +7,7 @@ import 'package:farm_tpf/data/repository/repository.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/controller/ChangeSupplyUsing.dart'; | |||
| @@ -18,6 +19,7 @@ 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/services.dart'; | |||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; | |||
| import 'package:get/get.dart'; | |||
| @@ -159,14 +161,9 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> { | |||
| } | |||
| Widget _quantityField() { | |||
| return TextFormField( | |||
| keyboardType: TextInputType.numberWithOptions(decimal: true), | |||
| inputFormatters: [ | |||
| ThousandsFormatter( | |||
| formatter: NumberFormat("#,###.##", "es"), allowFraction: true) | |||
| ], | |||
| decoration: InputDecoration(labelText: "Số lượng cây trồng"), | |||
| controller: _quantityController, | |||
| return WidgetTextFormFieldNumber( | |||
| hintValue: "Số lượng cây trồng", | |||
| textController: _quantityController, | |||
| onSaved: (newValue) { | |||
| _plant.quantity = newValue.parseDoubleThousand(); | |||
| }, | |||
| @@ -4,6 +4,7 @@ class ConstCommon { | |||
| static int kMaxAgeCache = 7; // 7days | |||
| static const String baseUrl = "http://tpf.aztrace.vn"; | |||
| static const String baseImageUrl = "http://tpf.aztrace.vn/upload/"; | |||
| static RegExp regExpDecimal = RegExp("[0-9,]"); | |||
| static const String apiDetailNursery = "api/activity-nursery"; | |||
| static const String apiDetailCropStatus = "api/activity-crop-status"; | |||
| @@ -46,6 +46,8 @@ const String label_province_empty_message = "Tỉnh/thành phố đang trống"; | |||
| const String label_district_empty = "Vui lòng chọn Quận/Huyện"; | |||
| const String label_district_empty_message = "Quận/Huyện đang trống"; | |||
| const String label_invalid_number = "Vui lòng nhập số"; | |||
| //Exception | |||
| const String exception_common = "Đã có lỗi xảy ra"; | |||
| const String exception_dio_cancle = "Truy vấn đến máy chủ bị huỷ"; | |||
| @@ -28,7 +28,8 @@ class Validators { | |||
| } | |||
| } | |||
| static String validNumber(String value, String errorMessage) { | |||
| static String validNumberOrEmpty(String value, String errorMessage) { | |||
| if (value.isEmpty) return null; | |||
| try { | |||
| var doubleValue = value.parseDoubleThousand(); | |||
| if (doubleValue > 0) { | |||