fix profile
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,53 +53,79 @@ class _DeliveryAddressListState extends State<DeliveryAddressList> {
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(
|
||||
children:
|
||||
getAddressList(context, shipmentModel.deliveryAddresses),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 20, bottom: 15, right: 15),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Container(
|
||||
width: 130,
|
||||
height: 40,
|
||||
child: FloatingActionButton.extended(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(DeliveryAddressEditor()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: Text(
|
||||
getLocalString(context, 'delivery_address.new_address'),
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(BottomUpPageRoute(DeliveryAddressEditor()));
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "delivery_address.new_address",
|
||||
color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (c, i) => Divider(
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
itemCount: shipmentModel.deliveryAddresses.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _row(context, shipmentModel.deliveryAddresses[index]);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getAddressList(
|
||||
BuildContext context, List<DeliveryAddress> addresses) {
|
||||
return addresses.asMap().entries.map((s) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
// Navigator.pop(context, s.value);
|
||||
},
|
||||
child: DeliveryAddressRow(shippingAddress: s.value, index: s.key),
|
||||
);
|
||||
}).toList();
|
||||
_row(BuildContext context, DeliveryAddress deliveryAddress) {
|
||||
return Row(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () => _select(deliveryAddress),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Icon(Icons.check,
|
||||
color:
|
||||
deliveryAddress.isDefault ? primaryColor : Colors.black26),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: DeliveryAddressRow(
|
||||
key: ValueKey(deliveryAddress.id),
|
||||
deliveryAddress: deliveryAddress,
|
||||
selectionCallback: (d) => _edit(context, deliveryAddress)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_edit(BuildContext context, DeliveryAddress deliveryAddress) {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(
|
||||
DeliveryAddressEditor(deliveryAddress: deliveryAddress)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _select(DeliveryAddress deliveryAddress) async {
|
||||
if (deliveryAddress.isDefault) {
|
||||
Navigator.pop(context);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
var deliveryAddressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
try {
|
||||
await deliveryAddressModel.selectDefalutDeliveryAddress(deliveryAddress);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,146 +1,78 @@
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
import 'delivery_address_editor.dart';
|
||||
typedef SelectionCallback(DeliveryAddress deliveryAddress);
|
||||
|
||||
class DeliveryAddressRow extends StatelessWidget {
|
||||
final DeliveryAddress shippingAddress;
|
||||
final int index;
|
||||
|
||||
const DeliveryAddressRow({Key key, this.shippingAddress, this.index})
|
||||
final DeliveryAddress deliveryAddress;
|
||||
final SelectionCallback selectionCallback;
|
||||
const DeliveryAddressRow(
|
||||
{Key key, this.deliveryAddress, this.selectionCallback})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
child: Column(
|
||||
return InkWell(
|
||||
onTap: selectionCallback == null
|
||||
? null
|
||||
: () => this.selectionCallback(deliveryAddress),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.pop(context, shippingAddress);
|
||||
},
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.fullName == null
|
||||
? ''
|
||||
: shippingAddress.fullName,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.addressLine1 == null
|
||||
? ''
|
||||
: shippingAddress.addressLine1,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.addressLine2 == null
|
||||
? ''
|
||||
: shippingAddress.addressLine2,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.city == null
|
||||
? ''
|
||||
: shippingAddress.city,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.state == null
|
||||
? ''
|
||||
: shippingAddress.state,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.country == null
|
||||
? ''
|
||||
: shippingAddress.country,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
shippingAddress.phoneNumber == null
|
||||
? ''
|
||||
: "Phone:${shippingAddress.phoneNumber}",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
line(context, deliveryAddress.fullName,
|
||||
iconData: MaterialCommunityIcons.account_arrow_left,
|
||||
color: primaryColor,
|
||||
fontSize: 16),
|
||||
line(context, deliveryAddress.phoneNumber,
|
||||
iconData: Icons.phone, color: primaryColor, fontSize: 16),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
padding: EdgeInsets.only(right: 30),
|
||||
icon: Icon(Icons.edit, color: Colors.black45),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(DeliveryAddressEditor(
|
||||
deliveryAddress: shippingAddress)),
|
||||
);
|
||||
}),
|
||||
IconButton(
|
||||
padding: EdgeInsets.only(right: 30),
|
||||
icon: Icon(Icons.delete, color: Colors.black45),
|
||||
onPressed: () async {
|
||||
await deliveryAddressModel
|
||||
.deleteDeliveryAddress(shippingAddress);
|
||||
})
|
||||
],
|
||||
line(context, deliveryAddress.addressLine1,
|
||||
iconData: Icons.location_on),
|
||||
line(
|
||||
context,
|
||||
deliveryAddress.addressLine2,
|
||||
),
|
||||
line(
|
||||
context,
|
||||
deliveryAddress.city,
|
||||
),
|
||||
line(context, deliveryAddress.state),
|
||||
],
|
||||
),
|
||||
),
|
||||
index == null
|
||||
? Container()
|
||||
: index == deliveryAddressModel.deliveryAddresses.length - 1
|
||||
? Container()
|
||||
: Divider(color: Colors.black)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget line(BuildContext context, String text,
|
||||
{IconData iconData, Color color, double fontSize}) {
|
||||
return Row(
|
||||
children: [
|
||||
iconData == null
|
||||
? SizedBox(width: 40)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8),
|
||||
child: Icon(iconData, color: Colors.black38),
|
||||
),
|
||||
Flexible(
|
||||
child: TextLocalStyle(
|
||||
context,
|
||||
text ?? "",
|
||||
fontSize: fontSize ?? 14,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ class DeliveryAddressModel extends BaseModel {
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
DeliveryAddress get defalutAddress =>
|
||||
deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => null);
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
super.privilegeChanged();
|
||||
@@ -61,4 +64,9 @@ class DeliveryAddressModel extends BaseModel {
|
||||
return Services.instance.deliveryAddressService
|
||||
.deleteDeliveryAddress(deliveryAddress);
|
||||
}
|
||||
|
||||
Future<void> selectDefalutDeliveryAddress(DeliveryAddress deliveryAddress) {
|
||||
return Services.instance.deliveryAddressService
|
||||
.selectDefalutDeliveryAddress(deliveryAddress);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user