| @@ -29,7 +29,6 @@ class FieldDateWidget extends StatefulWidget { | |||
| class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| ChangeDateTimePicker controller; | |||
| final textController = TextEditingController(); | |||
| var isShowError = false; | |||
| @override | |||
| void initState() { | |||
| @@ -47,26 +46,14 @@ class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| builder: (data) { | |||
| return SizedBox( | |||
| width: double.infinity, | |||
| height: Validators.stringNotNullOrEmpty(textController.text) && | |||
| validators != null | |||
| ? 65 | |||
| : widget.isValidated | |||
| ? 85 | |||
| : 85, | |||
| height: isShowError() ? 85 : 65, | |||
| child: Column( | |||
| crossAxisAlignment: CrossAxisAlignment.start, | |||
| children: [ | |||
| Validators.stringNotNullOrEmpty( | |||
| data?.selectedDateTime?.displayDateTime_DDMMYYYY_HHmm()) | |||
| isShowError() | |||
| ? Text( | |||
| widget.hint ?? '', | |||
| style: TextStyle( | |||
| color: Validators.stringNotNullOrEmpty( | |||
| textController.text) && | |||
| validators != null | |||
| ? Colors.black54 | |||
| : Colors.red, | |||
| fontSize: 13.0), | |||
| style: TextStyle(color: Colors.red, fontSize: 13.0), | |||
| ) | |||
| : Text( | |||
| '', | |||
| @@ -102,13 +89,9 @@ class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| border: Border( | |||
| bottom: BorderSide( | |||
| width: 0.5, | |||
| color: Validators.stringNotNullOrEmpty( | |||
| textController.text) && | |||
| validators != null | |||
| ? Colors.black54 | |||
| : widget.isValidated | |||
| ? Colors.red | |||
| : Colors.black54, | |||
| color: isShowError() | |||
| ? Colors.red | |||
| : Colors.black54, | |||
| )), | |||
| ), | |||
| child: Row( | |||
| @@ -137,10 +120,8 @@ class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| ], | |||
| )), | |||
| ), | |||
| Validators.stringNotNullOrEmpty(textController.text) && | |||
| validators != null | |||
| ? SizedBox() | |||
| : Text( | |||
| isShowError() | |||
| ? Text( | |||
| widget.isValidated | |||
| ? 'Vui lòng nhập ${widget.hint}' | |||
| : '', | |||
| @@ -149,7 +130,8 @@ class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| color: Colors.red, | |||
| fontWeight: FontWeight.normal), | |||
| textAlign: TextAlign.left, | |||
| ), | |||
| ) | |||
| : SizedBox(), | |||
| Container( | |||
| height: 0, | |||
| child: TextFormField( | |||
| @@ -166,4 +148,18 @@ class _FieldDateWidgetState extends State<FieldDateWidget> { | |||
| ); | |||
| }); | |||
| } | |||
| bool isShowError() { | |||
| if (widget.validator == null) { | |||
| return false; | |||
| } else { | |||
| if (widget.isValidated) { | |||
| return Validators.stringNotNullOrEmpty(textController.text) | |||
| ? false | |||
| : true; | |||
| } else { | |||
| return false; | |||
| } | |||
| } | |||
| } | |||
| } | |||