147 lines
4.2 KiB
Dart
147 lines
4.2 KiB
Dart
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/delivery_address/delivery_address_editor.dart';
|
|
import 'package:fcs/pages/main/util.dart';
|
|
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'model/delivery_address_model.dart';
|
|
import 'delivery_address_row.dart';
|
|
|
|
class DeliveryAddressList extends StatefulWidget {
|
|
final DeliveryAddress deliveryAddress;
|
|
final bool forSelection;
|
|
|
|
const DeliveryAddressList(
|
|
{Key key, this.deliveryAddress, this.forSelection = false})
|
|
: super(key: key);
|
|
@override
|
|
_DeliveryAddressListState createState() => _DeliveryAddressListState();
|
|
}
|
|
|
|
class _DeliveryAddressListState extends State<DeliveryAddressList> {
|
|
bool _isLoading = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var shipmentModel = Provider.of<DeliveryAddressModel>(context);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
leading: new IconButton(
|
|
icon: new Icon(Icons.close),
|
|
onPressed: () => Navigator.pop(context, widget.deliveryAddress),
|
|
),
|
|
backgroundColor: primaryColor,
|
|
title: LocalText(
|
|
context,
|
|
"delivery_addresses",
|
|
fontSize: 20,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
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]);
|
|
}),
|
|
)),
|
|
);
|
|
}
|
|
|
|
_row(BuildContext context, DeliveryAddress deliveryAddress) {
|
|
return Row(
|
|
children: [
|
|
widget.forSelection
|
|
? Container()
|
|
: 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) {
|
|
if (widget.forSelection) {
|
|
Navigator.pop(context, deliveryAddress);
|
|
return;
|
|
}
|
|
|
|
Navigator.push(
|
|
context,
|
|
BottomUpPageRoute(
|
|
DeliveryAddressEditor(deliveryAddress: deliveryAddress)),
|
|
);
|
|
}
|
|
|
|
Future<void> _select(DeliveryAddress deliveryAddress) async {
|
|
if (widget.forSelection) {
|
|
return;
|
|
}
|
|
|
|
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;
|
|
});
|
|
}
|
|
}
|
|
}
|