add validation in input form field
This commit is contained in:
@@ -19,6 +19,7 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
|
||||
bool _isLoading = false;
|
||||
late String dialCode;
|
||||
final _inviteFormKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -34,9 +35,17 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nameBox = InputText(
|
||||
labelTextKey: 'customer.name',
|
||||
iconData: Icons.person,
|
||||
controller: _nameController);
|
||||
labelTextKey: 'customer.name',
|
||||
iconData: Icons.person,
|
||||
controller: _nameController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert name";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -56,73 +65,88 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
}
|
||||
},
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
nameBox,
|
||||
SizedBox(height: 10),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.phone,
|
||||
color: primaryColor,
|
||||
body: Form(
|
||||
key: _inviteFormKey,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
nameBox,
|
||||
SizedBox(height: 10),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.phone,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border:
|
||||
Border.all(color: Colors.grey.shade400, width: 1),
|
||||
borderRadius: BorderRadius.all(Radius.circular(12.0))),
|
||||
child: CountryCodePicker(
|
||||
onChanged: _countryChange,
|
||||
initialSelection: dialCode,
|
||||
countryFilter: ['mm', 'us'],
|
||||
showCountryOnly: false,
|
||||
showOnlyCountryWhenClosed: false,
|
||||
alignLeft: false,
|
||||
textStyle: TextStyle(fontSize: 16, color: Colors.black87),
|
||||
searchDecoration: InputDecoration(
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.black, width: 1.0))),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border:
|
||||
Border.all(color: Colors.grey.shade400, width: 1),
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(12.0))),
|
||||
child: CountryCodePicker(
|
||||
onChanged: _countryChange,
|
||||
initialSelection: dialCode,
|
||||
countryFilter: ['mm', 'us'],
|
||||
showCountryOnly: false,
|
||||
showOnlyCountryWhenClosed: false,
|
||||
alignLeft: false,
|
||||
textStyle:
|
||||
TextStyle(fontSize: 16, color: Colors.black87),
|
||||
searchDecoration: InputDecoration(
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.black, width: 1.0))),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: TextFormField(
|
||||
controller: _phoneController,
|
||||
cursorColor: primaryColor,
|
||||
textAlign: TextAlign.left,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
labelText: getLocalString(context, "customer.phone"),
|
||||
labelStyle:
|
||||
TextStyle(fontSize: 16, color: Colors.grey),
|
||||
filled: true,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.grey, width: 1.0)),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: TextFormField(
|
||||
controller: _phoneController,
|
||||
cursorColor: primaryColor,
|
||||
textAlign: TextAlign.left,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
labelText:
|
||||
getLocalString(context, "customer.phone"),
|
||||
labelStyle:
|
||||
TextStyle(fontSize: 16, color: Colors.grey),
|
||||
filled: true,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey, width: 1.0)),
|
||||
errorStyle: TextStyle(
|
||||
color: dangerColor,
|
||||
)),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert phone no";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
fcsButton(context, getLocalString(context, "invite.btn"),
|
||||
callack: _invite),
|
||||
],
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
fcsButton(context, getLocalString(context, "invite.btn"),
|
||||
callack: _invite),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -138,9 +162,9 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
_invite() async {
|
||||
String userName = _nameController.text;
|
||||
String phoneNumber = dialCode + _phoneController.text;
|
||||
if (userName == "" || phoneNumber == "") {
|
||||
showMsgDialog(context, "Error", "Invalid name or phone number");
|
||||
return;
|
||||
|
||||
if (!_inviteFormKey.currentState!.validate()) {
|
||||
return null;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
|
||||
Reference in New Issue
Block a user