text validation and AppTextField
parent
93d2ec15aa
commit
4b55176b9d
@ -0,0 +1,37 @@
|
|||||||
|
import '../util/extenstions.dart';
|
||||||
|
|
||||||
|
class TextValidator{
|
||||||
|
|
||||||
|
// OWNER : Ibrahim albitar
|
||||||
|
// DATE : 19-04-2020
|
||||||
|
// DESCRIPTION : Text Validator.
|
||||||
|
|
||||||
|
String validateName(String value) {
|
||||||
|
if (value.isNullOrEmpty()||value.length < 3)
|
||||||
|
return 'Name must be more than 2 charater';
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String validateMobile(String value) {
|
||||||
|
if (value.isNullOrEmpty()||value.length != 10)
|
||||||
|
return 'Mobile Number must be of 10 digit';
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String validateIdNumber(String value) {
|
||||||
|
if (value.isNullOrEmpty())
|
||||||
|
return 'Please input valid number';
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String validateDate(String value) {
|
||||||
|
if (value.isNullOrEmpty())
|
||||||
|
return 'Please input valid date';
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
import 'package:doctor_app_flutter/config/size_config.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
// OWNER : Ibrahim albitar
|
||||||
|
// DATE : 19-04-2020
|
||||||
|
// DESCRIPTION : Custom Text Form Field for app.
|
||||||
|
|
||||||
|
class AppTextFormField extends FormField<String> {
|
||||||
|
|
||||||
|
AppTextFormField({
|
||||||
|
FormFieldSetter<String> onSaved,
|
||||||
|
FormFieldValidator<String> validator,
|
||||||
|
ValueChanged<String> onChanged,
|
||||||
|
GestureTapCallback onTap,
|
||||||
|
TextEditingController controller,
|
||||||
|
bool autovalidate = true,
|
||||||
|
TextInputType textInputType,
|
||||||
|
String hintText
|
||||||
|
}) : super(
|
||||||
|
onSaved: onSaved,
|
||||||
|
validator: validator,
|
||||||
|
autovalidate: autovalidate,
|
||||||
|
builder: (FormFieldState<String> state) {
|
||||||
|
return Column(
|
||||||
|
children: <Widget>[
|
||||||
|
TextFormField(
|
||||||
|
keyboardType: textInputType,
|
||||||
|
onChanged: onChanged?? (value){
|
||||||
|
state.didChange(value);
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: hintText,
|
||||||
|
hintStyle: TextStyle(fontSize: SizeConfig.textMultiplier * 2),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||||
|
borderSide: BorderSide(color: Color(0xff707070)),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||||
|
)
|
||||||
|
//BorderRadius.all(Radius.circular(20));
|
||||||
|
),
|
||||||
|
onTap: onTap,
|
||||||
|
controller: controller,
|
||||||
|
|
||||||
|
),
|
||||||
|
state.hasError?
|
||||||
|
Text(
|
||||||
|
state.errorText,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.red
|
||||||
|
),
|
||||||
|
) :
|
||||||
|
Container()
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue