Merge branch 'master' of sma/fcs into master

This commit is contained in:
tzw
2024-03-04 17:10:00 +06:30
committed by Gogs

View File

@@ -31,6 +31,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
bool _isLoading = false; bool _isLoading = false;
bool _isNew = true; bool _isNew = true;
final _deliveryFormKey=GlobalKey<FormState>();
@override @override
void initState() { void initState() {
@@ -60,12 +61,26 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
final fullName = InputText( final fullName = InputText(
labelTextKey: 'delivery_address.full_name', labelTextKey: 'delivery_address.full_name',
iconData: MaterialCommunityIcons.account_arrow_left, iconData: MaterialCommunityIcons.account_arrow_left,
controller: _nameController); controller: _nameController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if(value==null || value.isEmpty){
return"Please enter full name";
}
return null;
});
final addressLine1 = InputText( final addressLine1 = InputText(
labelTextKey: 'delivery_address.address_line1', labelTextKey: 'delivery_address.address_line1',
iconData: Icons.location_on, iconData: Icons.location_on,
controller: _address1Controller); controller: _address1Controller,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if(value==null || value.isEmpty){
return"Please enter address";
}
return null;
});
final addressLine2 = InputText( final addressLine2 = InputText(
labelTextKey: 'delivery_address.address_line2', labelTextKey: 'delivery_address.address_line2',
@@ -75,18 +90,39 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
final cityBox = InputText( final cityBox = InputText(
labelTextKey: 'delivery_address.city', labelTextKey: 'delivery_address.city',
iconData: Icons.location_city, iconData: Icons.location_city,
controller: _cityController); controller: _cityController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if(value==null || value.isEmpty){
return"Please enter city";
}
return null;
});
final regionBox = InputText( final regionBox = InputText(
labelTextKey: 'delivery_address.state_region', labelTextKey: 'delivery_address.state_region',
iconData: Entypo.location, iconData: Entypo.location,
controller: _stateController); controller: _stateController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if(value==null || value.isEmpty){
return"Please enter state/region";
}
return null;
});
final phoneNumberBox = InputText( final phoneNumberBox = InputText(
labelTextKey: 'delivery_address.phonenumber', labelTextKey: 'delivery_address.phonenumber',
iconData: Icons.phone, iconData: Icons.phone,
textInputType: TextInputType.phone, textInputType: TextInputType.phone,
controller: _phoneController); controller: _phoneController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if(value==null || value.isEmpty){
return"Please enter phone number";
}
return null;
});
final createBtn = fcsButton( final createBtn = fcsButton(
context, context,
@@ -128,7 +164,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
onPressed: _delete) onPressed: _delete)
], ],
), ),
body: Padding( body: Form(
key: _deliveryFormKey,
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10), padding: const EdgeInsets.only(left: 10.0, right: 10),
child: ListView(children: <Widget>[ child: ListView(children: <Widget>[
fullName, fullName,
@@ -147,6 +185,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
SizedBox(height: 10) SizedBox(height: 10)
]), ]),
), ),
),
)); ));
} }
@@ -168,23 +207,26 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
} }
Future<bool> _validate(DeliveryAddress deliveryAddress) async { Future<bool> _validate(DeliveryAddress deliveryAddress) async {
if (deliveryAddress.addressLine1 == "") { if(_deliveryFormKey.currentState!.validate()){
await showMsgDialog(context, "Error", "Invalid address line 1!");
return false; return false;
} }
// if (deliveryAddress.addressLine1 == "") {
// await showMsgDialog(context, "Error", "Invalid address line 1!");
// return false;
// }
if (deliveryAddress.city == null) { // if (deliveryAddress.city == null) {
await showMsgDialog(context, "Error", "Invalid city!"); // await showMsgDialog(context, "Error", "Invalid city!");
return false; // return false;
} // }
if (deliveryAddress.state == null) { // if (deliveryAddress.state == null) {
await showMsgDialog(context, "Error", "Invalid state!"); // await showMsgDialog(context, "Error", "Invalid state!");
return false; // return false;
} // }
if (deliveryAddress.phoneNumber == null) { // if (deliveryAddress.phoneNumber == null) {
await showMsgDialog(context, "Error", "Invalid phone number!"); // await showMsgDialog(context, "Error", "Invalid phone number!");
return false; // return false;
} // }
return true; return true;
} }
@@ -194,6 +236,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
if (!valid) { if (!valid) {
return; return;
} }
if (widget.user != null) { if (widget.user != null) {
deliveryAddress.userID = widget.user!.id; deliveryAddress.userID = widget.user!.id;
} }