add paginator
This commit is contained in:
@@ -27,9 +27,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.fullName == null
|
||||
box.deliveryAddress.fullName == null
|
||||
? ''
|
||||
: box.shippingAddress.fullName,
|
||||
: box.deliveryAddress.fullName,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.black,
|
||||
@@ -39,9 +39,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.addressLine1 == null
|
||||
box.deliveryAddress.addressLine1 == null
|
||||
? ''
|
||||
: box.shippingAddress.addressLine1,
|
||||
: box.deliveryAddress.addressLine1,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -49,9 +49,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.addressLine2 == null
|
||||
box.deliveryAddress.addressLine2 == null
|
||||
? ''
|
||||
: box.shippingAddress.addressLine2,
|
||||
: box.deliveryAddress.addressLine2,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -59,9 +59,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.city == null
|
||||
box.deliveryAddress.city == null
|
||||
? ''
|
||||
: box.shippingAddress.city,
|
||||
: box.deliveryAddress.city,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -69,9 +69,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.state == null
|
||||
box.deliveryAddress.state == null
|
||||
? ''
|
||||
: box.shippingAddress.state,
|
||||
: box.deliveryAddress.state,
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -79,9 +79,9 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shippingAddress.phoneNumber == null
|
||||
box.deliveryAddress.phoneNumber == null
|
||||
? ''
|
||||
: "Phone:${box.shippingAddress.phoneNumber}",
|
||||
: "Phone:${box.deliveryAddress.phoneNumber}",
|
||||
style: new TextStyle(
|
||||
fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
@@ -99,25 +99,14 @@ class BoxRow extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
"L${box.length}xW${box.weight}xH${box.height}",
|
||||
"L${box.length}xW${box.width}xH${box.height}",
|
||||
style: new TextStyle(fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.weight == null
|
||||
? ''
|
||||
: "Actual Weight:${box.weight.toString()}lb",
|
||||
style: new TextStyle(fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
box.shipmentWeight == null
|
||||
? ''
|
||||
: "Shipment Weight:${box.shipmentWeight.toString()}lb",
|
||||
"Actual Weight:${box.actualWeight.toString()}lb",
|
||||
style: new TextStyle(fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/domain/vo/radio.dart';
|
||||
import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
@@ -13,376 +14,145 @@ class ShipmentModel extends BaseModel {
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
List<RadioGroup> radioGroups1 = [
|
||||
RadioGroup(
|
||||
text: "FCS Pickup",
|
||||
index: 1,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "Courier Pickup",
|
||||
index: 2,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "FCS Drop-off",
|
||||
index: 3,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "Courier Drop-off",
|
||||
index: 4,
|
||||
),
|
||||
];
|
||||
List<Shipment> get shipments => _menuSelectedIndex == 1
|
||||
? _shipments
|
||||
: List<Shipment>.from(_delivered.values);
|
||||
|
||||
List<String> pickupTypes = [
|
||||
List<Shipment> _shipments = [];
|
||||
|
||||
Paginator _delivered;
|
||||
bool isLoading = false;
|
||||
int _menuSelectedIndex = 1;
|
||||
|
||||
set menuSelectedIndex(int index) {
|
||||
_menuSelectedIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get menuSelectedIndex => _menuSelectedIndex;
|
||||
|
||||
initData(bool forCustomer) {
|
||||
logout();
|
||||
_menuSelectedIndex = 1;
|
||||
_loadShipments(forCustomer);
|
||||
_delivered = _getDeliveredExample(forCustomer);
|
||||
_delivered.load();
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (_delivered != null) _delivered.close();
|
||||
if (listener != null) await listener.cancel();
|
||||
_shipments = [];
|
||||
}
|
||||
|
||||
Future<void> loadMore({bool isCustomer}) async {
|
||||
if (menuSelectedIndex == 1)
|
||||
return; // when delivered menu is not selected return
|
||||
if (_delivered.ended) return;
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
await _delivered.load(onFinished: () {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> refresh({bool isCustomer}) async {
|
||||
if (menuSelectedIndex == 1)
|
||||
return; // when delivered menu is not selected return
|
||||
await _delivered.refresh(onFinished: () {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
Paginator _getDelivered(bool isCustomer) {
|
||||
if (!isCustomer) {
|
||||
if (user == null ||
|
||||
!((user.hasPackages() ||
|
||||
user.hasReceiving() ||
|
||||
user.hasProcessing()))) throw "No privilege";
|
||||
}
|
||||
var pageQuery = Firestore.instance
|
||||
.collection("/$packages_collection")
|
||||
.where("is_delivered", isEqualTo: true)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
if (isCustomer) {
|
||||
pageQuery = pageQuery.where("user_id", isEqualTo: user.id);
|
||||
}
|
||||
pageQuery = pageQuery.orderBy("current_status_date", descending: true);
|
||||
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
|
||||
return Shipment.fromMap(data, id);
|
||||
});
|
||||
return paginator;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
Paginator _getDeliveredExample(bool onlyFcs) {
|
||||
count = 1;
|
||||
var pageQuery = Firestore.instance
|
||||
.collection(
|
||||
"/users/8OTfsbVvsUOn1SLxy1OrKk7Y_yNKkVoGalPcIlcHnAY/messages")
|
||||
.orderBy("date", descending: true);
|
||||
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
|
||||
var m = Message.fromMap(data, id);
|
||||
return Shipment(
|
||||
id: m.id,
|
||||
shipmentNumber: m.message,
|
||||
currentStatus: m.senderName,
|
||||
pickupDate: m.date,
|
||||
);
|
||||
});
|
||||
return paginator;
|
||||
}
|
||||
|
||||
Future<void> _loadShipments(bool forCustomer) async {
|
||||
if (user == null) return;
|
||||
if (!forCustomer && !user.hasShipment()) return;
|
||||
String path = "/$shipments_collection";
|
||||
if (listener != null) listener.cancel();
|
||||
_shipments = [];
|
||||
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("is_delivered", isEqualTo: false)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
|
||||
if (forCustomer) {
|
||||
q = q.where("user_id", isEqualTo: user.id);
|
||||
}
|
||||
|
||||
listener = q.snapshots().listen((QuerySnapshot snapshot) {
|
||||
_shipments.clear();
|
||||
_shipments = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Shipment.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> shipmentTypes = [
|
||||
shipment_local_pickup,
|
||||
shipment_courier_pickup,
|
||||
shipment_local_dropoff,
|
||||
shipment_courier_dropoff
|
||||
];
|
||||
|
||||
List<RadioGroup> get radioGroups {
|
||||
List<RadioGroup> radioGroups = [
|
||||
RadioGroup(
|
||||
text: "Local Pickup",
|
||||
index: 1,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "Courier Pickup",
|
||||
index: 2,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "Local Drop-off",
|
||||
index: 3,
|
||||
),
|
||||
RadioGroup(
|
||||
text: "Courier Drop-off",
|
||||
index: 4,
|
||||
),
|
||||
];
|
||||
return radioGroups;
|
||||
}
|
||||
|
||||
List<Shipment> get pickups {
|
||||
List<Shipment> pickups = [
|
||||
Shipment(
|
||||
id: "S200412 - 12 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pending',
|
||||
date: DateTime(2020, 5, 1),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
isCourier: true,
|
||||
radioIndex: 2,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200125 - 12 May 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Confirmed',
|
||||
date: DateTime(2020, 5, 6),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 13 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Pickuped",
|
||||
date: DateTime(2020, 5, 9),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
radioIndex: 3,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200412 - 12 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pickuped',
|
||||
date: DateTime(2020, 5, 15),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200125 - 12 May 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pickuped',
|
||||
date: DateTime(2020, 5, 20),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 13 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Pickuped",
|
||||
date: DateTime(2020, 5, 21),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 10 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Canceled",
|
||||
date: DateTime(2020, 5, 25),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 6 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Canceled",
|
||||
date: DateTime(2020, 5, 27),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
];
|
||||
return pickups;
|
||||
}
|
||||
|
||||
List<Shipment> pickups1 = [
|
||||
Shipment(
|
||||
id: "S200412 - 12 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pending',
|
||||
date: DateTime(2020, 5, 1),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
isCourier: true,
|
||||
radioIndex: 2,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200125 - 12 May 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Confirmed',
|
||||
date: DateTime(2020, 5, 6),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 13 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Pickuped",
|
||||
date: DateTime(2020, 5, 9),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
radioIndex: 3,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200412 - 12 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pickuped',
|
||||
date: DateTime(2020, 5, 15),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200125 - 12 May 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: 'Pickuped',
|
||||
date: DateTime(2020, 5, 20),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 13 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Pickuped",
|
||||
date: DateTime(2020, 5, 21),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 10 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Canceled",
|
||||
date: DateTime(2020, 5, 25),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
Shipment(
|
||||
id: "S200441 - 6 Apr 2020",
|
||||
userName: "Ko Kyaw Nyi",
|
||||
phoneNumber: '+959111111111',
|
||||
fromTime: '1PM',
|
||||
toTime: '3PM',
|
||||
numberOfPackage: 5,
|
||||
weight: 25,
|
||||
status: "Canceled",
|
||||
date: DateTime(2020, 5, 27),
|
||||
address: '154-19 64th Ave.\nFlushing, NY 11367',
|
||||
handlingFee: 50,
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
]),
|
||||
];
|
||||
|
||||
List<Shipment> get canceled {
|
||||
List<Shipment> _p = pickups.where((e) => e.status == "Canceled").toList()
|
||||
..sort((e1, e2) {
|
||||
return e2.date.compareTo(e1.date);
|
||||
});
|
||||
return _p;
|
||||
}
|
||||
|
||||
List<Shipment> get completed {
|
||||
return pickups.where((e) => e.status == "Pickuped").toList()
|
||||
..sort((e1, e2) {
|
||||
return e2.date.compareTo(e1.date);
|
||||
});
|
||||
}
|
||||
|
||||
List<Shipment> get upcoming {
|
||||
return pickups
|
||||
.where((e) =>
|
||||
e.status == "Pending" ||
|
||||
e.status == "Confirmed" ||
|
||||
e.status == "Processed" ||
|
||||
e.status == "Rescheduled")
|
||||
.toList()
|
||||
..sort((e1, e2) {
|
||||
return e2.date.compareTo(e1.date);
|
||||
});
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
// pickups = [];
|
||||
Future<void> createShipment(Shipment shipment) {
|
||||
return Services.instance.shipmentService.createShipment(shipment);
|
||||
}
|
||||
|
||||
Future<void> updateShipment(Shipment shipment) {
|
||||
return Services.instance.shipmentService.updateShipment(shipment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/box/cargo_type_editor.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/rates/model/shipment_rate_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';
|
||||
@@ -37,10 +35,8 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
Box _box;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
DeliveryAddress _deliveryAddress;
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
List<CargoType> cargos = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -52,22 +48,26 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
if (widget.box != null) {
|
||||
_box = widget.box;
|
||||
_deliveryAddress = _box.shippingAddress;
|
||||
_isNew = false;
|
||||
_lengthCtl.text = _box.length.toString();
|
||||
_widthCtl.text = _box.width.toString();
|
||||
_heightCtl.text = _box.height.toString();
|
||||
} else {
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_deliveryAddress = shipmentModel.defalutAddress;
|
||||
|
||||
_isNew = true;
|
||||
_box = Box();
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
_heightCtl.text = "0";
|
||||
_box = Box(cargoTypes: []);
|
||||
_box.deliveryAddress = shipmentModel.defalutAddress;
|
||||
|
||||
_lengthCtl.text = "12";
|
||||
_widthCtl.text = "12";
|
||||
_heightCtl.text = "12";
|
||||
}
|
||||
_lengthCtl.addListener(_calShipmentWeight);
|
||||
_widthCtl.addListener(_calShipmentWeight);
|
||||
_heightCtl.addListener(_calShipmentWeight);
|
||||
_calShipmentWeight();
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
@@ -75,7 +75,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||
setState(() {
|
||||
shipmentWeight = l * w * h / volumetricRatio;
|
||||
shipmentWeight = (l * w * h / volumetricRatio).ceilToDouble();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
);
|
||||
final createBtn = LocalButton(
|
||||
textKey: "shipment.box.add",
|
||||
callBack: _creatCarton,
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -182,19 +183,19 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
shipmentWeightBox,
|
||||
LocalTitle(textKey: "shipment.box.delivery"),
|
||||
DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
labelKey: "shipment.box.delivery",
|
||||
onTap: () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
this._deliveryAddress = d;
|
||||
_box.deliveryAddress = d;
|
||||
});
|
||||
}),
|
||||
createBtn
|
||||
@@ -206,11 +207,11 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(BuildContext context) {
|
||||
if (cargos == null || cargos == null) {
|
||||
if (_box.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
int total = 0;
|
||||
var rows = cargos.map((c) {
|
||||
double total = 0;
|
||||
var rows = _box.cargoTypes.map((c) {
|
||||
total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
@@ -258,7 +259,6 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
|
||||
)),
|
||||
MyDataCell(
|
||||
Padding(
|
||||
@@ -278,14 +278,24 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
cargos.remove(cargo);
|
||||
cargos.add(cargo);
|
||||
_box.cargoTypes.remove(cargo);
|
||||
_box.cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
cargos.remove(cargo);
|
||||
_box.cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_creatCarton() {
|
||||
double l = double.parse(_lengthCtl.text, (s) => 0);
|
||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||
_box.length = l;
|
||||
_box.width = w;
|
||||
_box.height = h;
|
||||
Navigator.pop(context, _box);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/box/model/box_model.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/shipment/model/shipment_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';
|
||||
@@ -21,7 +20,6 @@ import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:fcs/pages/widgets/title_with_add_button.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
@@ -32,8 +30,6 @@ import 'package:provider/provider.dart';
|
||||
import 'box_row.dart';
|
||||
import 'shipment_box_editor.dart';
|
||||
|
||||
enum SingingCharacter { lafayette, jefferson }
|
||||
|
||||
class ShipmentEditor extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
ShipmentEditor({this.shipment});
|
||||
@@ -63,46 +59,42 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
TextEditingController _handlingFeeController = new TextEditingController();
|
||||
|
||||
Shipment _pickUp;
|
||||
Shipment _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
bool _isNew;
|
||||
DeliveryAddress _pickupAddress = new DeliveryAddress();
|
||||
|
||||
int _currVal = 1;
|
||||
String _selectedPickupType;
|
||||
String _selectedShipmentType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedPickupType = shipment_local_pickup;
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
|
||||
if (widget.shipment != null) {
|
||||
_isNew = false;
|
||||
_pickUp = widget.shipment;
|
||||
_addressEditingController.text = _pickUp.address;
|
||||
_fromTimeEditingController.text = _pickUp.fromTime;
|
||||
_toTimeEditingController.text = _pickUp.toTime;
|
||||
_noOfPackageEditingController.text = _pickUp.numberOfPackage.toString();
|
||||
_weightEditingController.text = _pickUp.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
_handlingFeeController.text = numberFormatter.format(_pickUp.handlingFee);
|
||||
_currVal = _pickUp.radioIndex;
|
||||
_shipment = widget.shipment;
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
||||
_weightEditingController.text = _shipment.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
// _handlingFeeController.text =
|
||||
// numberFormatter.format(_shipment.handlingFee);
|
||||
_currVal = _shipment.radioIndex;
|
||||
} else {
|
||||
_isNew = true;
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
_fromTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
||||
_toTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
||||
List<CargoType> _cargoTypes = [
|
||||
CargoType(name: 'General Cargo', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous Cargo', weight: 30)
|
||||
];
|
||||
_pickUp = Shipment(cargoTypes: _cargoTypes);
|
||||
_shipment = Shipment(boxes: []);
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_shipment.pickupAddress = shipmentModel.defalutAddress;
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
}
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_pickupAddress = shipmentModel.defalutAddress;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -110,8 +102,6 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
SingingCharacter _character = SingingCharacter.lafayette;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
@@ -149,20 +139,20 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
backgroundColor: primaryColor,
|
||||
);
|
||||
final pickupAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _pickupAddress,
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
onTap: () async {
|
||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||
DeliveryAddress address = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _pickupAddress,
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
if (address == null) return;
|
||||
setState(() {
|
||||
this._pickupAddress = d;
|
||||
_shipment.pickupAddress = address;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -174,15 +164,16 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
var shipmentTypeBox = LocalDropdown<String>(
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectedPickupType = v;
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
},
|
||||
iconData: SimpleLineIcons.direction,
|
||||
selectedValue: _selectedPickupType,
|
||||
values: pickupModel.pickupTypes,
|
||||
selectedValue: _selectedShipmentType,
|
||||
values: pickupModel.shipmentTypes,
|
||||
);
|
||||
final createBtn = LocalButton(
|
||||
textKey: "shipment.create",
|
||||
callBack: _create,
|
||||
);
|
||||
|
||||
final updateBtn = LocalButton(
|
||||
@@ -216,11 +207,11 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
children: <Widget>[
|
||||
LocalTitle(textKey: "shipment.type"),
|
||||
LocalRadioButtons(
|
||||
values: pickupModel.pickupTypes,
|
||||
selectedValue: _selectedPickupType,
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _selectedShipmentType,
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectedPickupType = v;
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
}),
|
||||
// handlingFeeBox,
|
||||
@@ -240,17 +231,18 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
onPressed: () async {
|
||||
Box box = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentBoxEditor()),
|
||||
);
|
||||
_addBox(box);
|
||||
},
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: getBoxList(context, boxModel.boxes),
|
||||
children: getBoxList(context, _shipment.boxes),
|
||||
),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
],
|
||||
@@ -263,14 +255,67 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
List<Widget> getBoxList(BuildContext context, List<Box> boxes) {
|
||||
return boxes.asMap().entries.map((_box) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
onTap: () async {
|
||||
Box box = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentBoxEditor(box: _box.value)));
|
||||
_saveBox(box);
|
||||
},
|
||||
child: BoxRow(box: _box.value),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: BoxRow(box: _box.value)),
|
||||
InkWell(
|
||||
onTap: () => _removeBox(_box.value),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.remove, color: primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_addBox() {}
|
||||
_addBox(Box box) {
|
||||
if (box == null) return;
|
||||
_shipment.boxes.add(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_saveBox(Box box) {
|
||||
if (box == null) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_removeBox(Box box) {
|
||||
if (box == null) return;
|
||||
_shipment.boxes.remove(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_create() async {
|
||||
_shipment.shipmentType = this._selectedShipmentType;
|
||||
_shipment.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment.pickupTimeStart = _fromTimeEditingController.text;
|
||||
_shipment.pickupTimeEnd = _toTimeEditingController.text;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
} else {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
248
lib/pages/shipment/shipment_info.dart
Normal file
248
lib/pages/shipment/shipment_info.dart
Normal file
@@ -0,0 +1,248 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/box/model/box_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/shipment/model/shipment_model.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/input_date.dart';
|
||||
import 'package:fcs/pages/widgets/input_time.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'box_row.dart';
|
||||
|
||||
class ShipmentInfo extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
ShipmentInfo({this.shipment});
|
||||
|
||||
@override
|
||||
_ShipmentInfoState createState() => _ShipmentInfoState();
|
||||
}
|
||||
|
||||
class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
final numberFormatter = new NumberFormat("#,###");
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
|
||||
TextEditingController _addressEditingController = new TextEditingController();
|
||||
TextEditingController _fromTimeEditingController =
|
||||
new TextEditingController();
|
||||
TextEditingController _toTimeEditingController = new TextEditingController();
|
||||
TextEditingController _noOfPackageEditingController =
|
||||
new TextEditingController();
|
||||
TextEditingController _weightEditingController = new TextEditingController();
|
||||
TextEditingController _recipientNameEditingController =
|
||||
new TextEditingController();
|
||||
TextEditingController _recipientPhoneEditingController =
|
||||
new TextEditingController();
|
||||
TextEditingController _recipientAddressEditingController =
|
||||
new TextEditingController();
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
TextEditingController _handlingFeeController = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
|
||||
int _currVal = 1;
|
||||
String _selectedShipmentType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
_shipment = widget.shipment;
|
||||
|
||||
if (widget.shipment != null) {
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
||||
_weightEditingController.text = _shipment.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
// _handlingFeeController.text =
|
||||
// numberFormatter.format(_shipment.handlingFee);
|
||||
_currVal = _shipment.radioIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
||||
|
||||
final fromTimeBox = InputTime(
|
||||
labelTextKey: 'shipment.from',
|
||||
iconData: Icons.timer,
|
||||
controller: _fromTimeEditingController);
|
||||
|
||||
final toTimeBox = Container(
|
||||
width: 150,
|
||||
child: InputTime(
|
||||
iconData: Icons.timer_off,
|
||||
labelTextKey: 'shipment.to',
|
||||
controller: _toTimeEditingController));
|
||||
|
||||
final pickupDateBox = InputDate(
|
||||
labelTextKey: "shipment.date",
|
||||
iconData: Icons.date_range,
|
||||
controller: _pickupDate,
|
||||
);
|
||||
final localDropoffAddress = DisplayText(
|
||||
iconData: Icons.location_on,
|
||||
labelTextKey: "Local Dropoff Address",
|
||||
text: mainModel.setting.usaAddress);
|
||||
final curierDropoffAddress = FloatingActionButton.extended(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.arrow_right),
|
||||
label: Text(
|
||||
'Visit courier websie for nearest drop-off',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
);
|
||||
final pickupAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
onTap: () async {
|
||||
DeliveryAddress address = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
)),
|
||||
);
|
||||
if (address == null) return;
|
||||
setState(() {
|
||||
_shipment.pickupAddress = address;
|
||||
});
|
||||
},
|
||||
);
|
||||
var boxModel = Provider.of<BoxModel>(context);
|
||||
var handlingFeeBox = DisplayText(
|
||||
labelTextKey: "shipment.handling.fee",
|
||||
text: "10",
|
||||
iconData: FontAwesomeIcons.moneyBill);
|
||||
var shipmentTypeBox = LocalDropdown<String>(
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
},
|
||||
iconData: SimpleLineIcons.direction,
|
||||
selectedValue: _selectedShipmentType,
|
||||
values: pickupModel.shipmentTypes,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(
|
||||
CupertinoIcons.back,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
"shipment.info",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit, color: primaryColor),
|
||||
onPressed: _edit,
|
||||
)
|
||||
]),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
LocalTitle(textKey: "shipment.type"),
|
||||
LocalRadioButtons(
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _selectedShipmentType,
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
}),
|
||||
// handlingFeeBox,
|
||||
// shipmentTypeBox,
|
||||
LocalTitle(textKey: "shipment.location"),
|
||||
pickupAddressBox,
|
||||
LocalTitle(textKey: "shipment.date.time"),
|
||||
pickupDateBox,
|
||||
fromTimeBox,
|
||||
toTimeBox,
|
||||
// localDropoffAddress,
|
||||
// curierDropoffAddress,
|
||||
LocalTitle(
|
||||
textKey: "boxes.name",
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {},
|
||||
),
|
||||
),
|
||||
// Column(
|
||||
// children: getBoxList(context, _shipment.boxes),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getBoxList(BuildContext context, List<Box> boxes) {
|
||||
return boxes.asMap().entries.map((_box) {
|
||||
return InkWell(
|
||||
onTap: () async {},
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: BoxRow(box: _box.value)),
|
||||
InkWell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.remove, color: primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_edit() {}
|
||||
}
|
||||
@@ -15,17 +15,28 @@ import 'shipment_editor.dart';
|
||||
import 'shipment_list_row.dart';
|
||||
|
||||
class ShipmentList extends StatefulWidget {
|
||||
final bool forCustomer;
|
||||
|
||||
const ShipmentList({Key key, this.forCustomer = true}) : super(key: key);
|
||||
@override
|
||||
_ShipmentListState createState() => _ShipmentListState();
|
||||
}
|
||||
|
||||
class _ShipmentListState extends State<ShipmentList> {
|
||||
bool _isLoading = false;
|
||||
bool _showDelivered = false;
|
||||
var _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.addListener(() async {
|
||||
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
|
||||
Provider.of<ShipmentModel>(context, listen: false)
|
||||
.loadMore(isCustomer: widget.forCustomer);
|
||||
}
|
||||
});
|
||||
|
||||
Provider.of<ShipmentModel>(context, listen: false).initData(false);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -35,7 +46,7 @@ class _ShipmentListState extends State<ShipmentList> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var pickupModel = Provider.of<ShipmentModel>(context);
|
||||
ShipmentModel shipmentModel = Provider.of<ShipmentModel>(context);
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
@@ -43,7 +54,7 @@ class _ShipmentListState extends State<ShipmentList> {
|
||||
LocalPopupMenu(id: 2, textKey: "shipment.popupmenu.delivered")
|
||||
],
|
||||
popupMenuCallback: (p) => this.setState(() {
|
||||
_showDelivered = p.id == 2;
|
||||
shipmentModel.menuSelectedIndex = p.id;
|
||||
}),
|
||||
);
|
||||
return LocalProgress(
|
||||
@@ -72,25 +83,53 @@ class _ShipmentListState extends State<ShipmentList> {
|
||||
popupMenu
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newPickup();
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "shipment.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
floatingActionButton: shipmentModel.menuSelectedIndex == 1
|
||||
? FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newPickup();
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label:
|
||||
LocalText(context, "shipment.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
)
|
||||
: Container(),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
child: ListView.separated(
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: shipmentModel.shipments.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return ShipmentListRow(
|
||||
pickUp: shipmentModel.shipments[index]);
|
||||
}),
|
||||
onRefresh: () =>
|
||||
shipmentModel.refresh(isCustomer: widget.forCustomer),
|
||||
),
|
||||
),
|
||||
shipmentModel.isLoading
|
||||
? Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
color: primaryColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Loading...",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
body: new ListView.separated(
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: pickupModel.pickups.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return ShipmentListRow(pickUp: pickupModel.pickups[index]);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
import '../main/util.dart';
|
||||
import 'shipment_editor.dart';
|
||||
import 'shipment_info.dart';
|
||||
|
||||
class ShipmentListRow extends StatefulWidget {
|
||||
final Shipment pickUp;
|
||||
@@ -36,13 +37,12 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('_pickup $_pickUp');
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentEditor(shipment: _pickUp)));
|
||||
builder: (context) => ShipmentInfo(shipment: _pickUp)));
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
@@ -64,7 +64,7 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
_pickUp.id == null ? '' : _pickUp.id,
|
||||
_pickUp.shipmentNumber,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
@@ -90,7 +90,7 @@ class _ShipmentListRowState extends State<ShipmentListRow> {
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: getStatus(_pickUp.status),
|
||||
child: getStatus(_pickUp.currentStatus),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
|
||||
|
||||
Reference in New Issue
Block a user