add shipments
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||
@@ -27,6 +34,7 @@ class PackageInfo extends StatefulWidget {
|
||||
class _PackageInfoState extends State<PackageInfo> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
Package _package;
|
||||
DeliveryAddress _deliveryAddress;
|
||||
bool _isLoading = false;
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
|
||||
@@ -41,6 +49,12 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
_package = package;
|
||||
multiImgController.setImageUrls = package.photoUrls;
|
||||
});
|
||||
if (!widget.isSearchResult) {
|
||||
DeliveryAddressModel deliveryAddressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_deliveryAddress = deliveryAddressModel
|
||||
.getLocalDeliveryAddress(package.deliveryAddressID);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -50,6 +64,9 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String id = Provider.of<MainModel>(context).user.id;
|
||||
bool owner = _package.userID == id;
|
||||
|
||||
final trackingIdBox = DisplayText(
|
||||
text: _package.trackingID,
|
||||
labelTextKey: "package.tracking.id",
|
||||
@@ -85,6 +102,22 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
controller: multiImgController,
|
||||
title: "Receipt File",
|
||||
);
|
||||
final deliveryAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "package.delivery.address",
|
||||
onTap: owner
|
||||
? () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
BottomUpPageRoute(DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
_changeDeliverayAddress(d);
|
||||
}
|
||||
: null,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -118,6 +151,7 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
_package.photoUrls.length == 0 ? Container() : img,
|
||||
widget.isSearchResult ? Container() : descBox,
|
||||
remarkBox,
|
||||
deliveryAddressBox,
|
||||
StatusTree(
|
||||
shipmentHistory: _package.shipmentHistory,
|
||||
currentStatus: _package.currentStatus),
|
||||
@@ -133,37 +167,29 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
);
|
||||
}
|
||||
|
||||
List<TimelineModel> _models() {
|
||||
if (_package.shipmentHistory == null) return [];
|
||||
return _package.shipmentHistory
|
||||
.map((e) => TimelineModel(
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(e.status,
|
||||
style: TextStyle(
|
||||
color: e.done ? primaryColor : Colors.grey,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Text(dateFormat.format(e.date)),
|
||||
],
|
||||
),
|
||||
),
|
||||
iconBackground: e.done ? primaryColor : Colors.grey,
|
||||
icon: Icon(
|
||||
e.status == "shipped"
|
||||
? Ionicons.ios_airplane
|
||||
: e.status == "delivered"
|
||||
? MaterialCommunityIcons.truck_fast
|
||||
: e.status == "packed"
|
||||
? MaterialCommunityIcons.package
|
||||
: e.status == "processed"
|
||||
? FontAwesome.dropbox
|
||||
: MaterialCommunityIcons.inbox_arrow_down,
|
||||
color: Colors.white,
|
||||
)))
|
||||
.toList();
|
||||
_changeDeliverayAddress(DeliveryAddress deliveryAddress) async {
|
||||
if (deliveryAddress == null) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
DeliveryAddressModel deliveryAddressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
try {
|
||||
await packageModel.changeDeliveryAddress(_package, deliveryAddress);
|
||||
var da =
|
||||
await deliveryAddressModel.getDeliveryAddress(deliveryAddress.id);
|
||||
setState(() {
|
||||
_deliveryAddress = da;
|
||||
});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user