fix profile

This commit is contained in:
Sai Naw Wun
2020-10-11 02:17:23 +06:30
parent b0ce53f856
commit 32e6be2abd
42 changed files with 938 additions and 626 deletions

View File

@@ -23,25 +23,28 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
TextEditingController _address2Controller = new TextEditingController();
TextEditingController _cityController = new TextEditingController();
TextEditingController _stateController = new TextEditingController();
TextEditingController _countryController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
DeliveryAddress _deliveryAddress = new DeliveryAddress();
bool _isLoading = false;
bool _isNew = true;
@override
void initState() {
super.initState();
if (widget.deliveryAddress != null) {
_isNew = false;
_deliveryAddress = widget.deliveryAddress;
_nameController.text = _deliveryAddress.fullName;
_address1Controller.text = _deliveryAddress.addressLine1;
_address2Controller.text = _deliveryAddress.addressLine2;
_cityController.text = _deliveryAddress.city;
_stateController.text = _deliveryAddress.state;
_countryController.text = _deliveryAddress.country;
_phoneController.text = _deliveryAddress.phoneNumber;
} else {
_cityController.text = "Yangon";
_stateController.text = "Yangon";
}
}
@@ -52,9 +55,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
@override
Widget build(BuildContext context) {
final usaAddress = InputText(
final fullName = InputText(
labelTextKey: 'delivery_address.full_name',
iconData: Icons.text_format,
iconData: MaterialCommunityIcons.account_arrow_left,
controller: _nameController);
final addressLine1 = InputText(
@@ -77,14 +80,10 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
iconData: Entypo.location,
controller: _stateController);
final countryBox = InputText(
labelTextKey: 'delivery_address.country',
iconData: Entypo.flag,
controller: _countryController);
final phoneNumberBox = InputText(
labelTextKey: 'delivery_address.phonenumber',
iconData: Icons.phone,
textInputType: TextInputType.phone,
controller: _phoneController);
final createBtn = fcsButton(
@@ -100,52 +99,43 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: LocalText(
context,
'delivery_address',
color: Colors.white,
fontSize: 20,
),
actions: [IconButton(icon: Icon(Icons.delete), onPressed: _delete)],
),
backgroundColor: primaryColor,
title: LocalText(
context,
'user.form.shipping_address',
color: Colors.white,
fontSize: 20,
),
),
body: Card(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10),
child: ListView(children: <Widget>[
usaAddress,
SizedBox(height: 5),
addressLine1,
SizedBox(height: 5),
addressLine2,
SizedBox(height: 5),
cityBox,
SizedBox(height: 5),
regionBox,
SizedBox(height: 5),
countryBox,
SizedBox(height: 5),
phoneNumberBox,
SizedBox(height: 10),
]),
)),
widget.deliveryAddress == null ? createBtn : updateBtn,
body: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10),
child: ListView(children: <Widget>[
fullName,
SizedBox(height: 5),
phoneNumberBox,
SizedBox(height: 10),
addressLine1,
SizedBox(height: 5),
addressLine2,
SizedBox(height: 5),
cityBox,
SizedBox(height: 5),
regionBox,
SizedBox(height: 5),
_isNew ? createBtn : updateBtn,
SizedBox(height: 10)
],
]),
),
),
),
);
));
}
DeliveryAddress _getPayload() {
@@ -158,7 +148,6 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
deliveryAddress.addressLine2 = _address2Controller.text;
deliveryAddress.city = _cityController.text;
deliveryAddress.state = _stateController.text;
deliveryAddress.country = _countryController.text;
deliveryAddress.phoneNumber = _phoneController.text;
} catch (e) {
showMsgDialog(context, "Error", e.toString()); // shold never happen
@@ -180,10 +169,6 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
await showMsgDialog(context, "Error", "Invalid state!");
return false;
}
if (deliveryAddress.country == null) {
await showMsgDialog(context, "Error", "Invalid country!");
return false;
}
if (deliveryAddress.phoneNumber == null) {
await showMsgDialog(context, "Error", "Invalid phone number!");
return false;
@@ -216,7 +201,6 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
Future<void> _update() async {
DeliveryAddress deliveryAddress = _getPayload();
print('deliveryAddress => ${deliveryAddress.country}');
bool valid = await _validate(deliveryAddress);
if (!valid) {
return;
@@ -237,4 +221,26 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
});
}
}
_delete() {
showConfirmDialog(context, "delivery_address.delete.confirm", _deleteDA);
}
_deleteDA() async {
setState(() {
_isLoading = true;
});
try {
DeliveryAddressModel deliveryAddressModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}