update carton
This commit is contained in:
@@ -49,7 +49,7 @@ class CartonDataProvider {
|
||||
.collection(path)
|
||||
.where("carton_number", isEqualTo: term)
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cargos])
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("user_name")
|
||||
|
||||
@@ -78,7 +78,7 @@ const shipment_courier_dropoff = "Courier drop off";
|
||||
|
||||
//Carton types
|
||||
const carton_from_packages = "From packages";
|
||||
const carton_from_cargos="From cargos";
|
||||
const carton_from_cartons="From cartons";
|
||||
const carton_from_shipments = "From shipments";
|
||||
const carton_mix_carton = "Mix carton";
|
||||
const carton_small_bag = "Small bag";
|
||||
|
||||
@@ -40,6 +40,7 @@ class Carton {
|
||||
String mixCartonNumber;
|
||||
String cartonSizeID;
|
||||
String cartonSizeName;
|
||||
double cartonWeight;
|
||||
|
||||
int rate;
|
||||
int weight;
|
||||
@@ -174,7 +175,8 @@ class Carton {
|
||||
this.cartonSizeName,
|
||||
this.mixBoxType,
|
||||
this.mixCartons,
|
||||
this.mixCartonIDs});
|
||||
this.mixCartonIDs,
|
||||
this.cartonWeight});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
List _cargoTypes = cargoTypes?.map((c) => c.toMap())?.toList() ?? [];
|
||||
@@ -249,6 +251,7 @@ class Carton {
|
||||
senderFCSID: map['sender_fcs_id'],
|
||||
senderName: map['sender_name'],
|
||||
mixCartonIDs: List<String>.from(map['mix_carton_ids'] ?? []),
|
||||
cartonWeight: (map['carton_weight'] ?? 0).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<CargoType> _cargoTypes = [];
|
||||
|
||||
@@ -116,7 +115,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
if (isFromPackages) _loadPackages();
|
||||
|
||||
if (!isMixBox) {
|
||||
_getDeliverAddresses();
|
||||
_getCartonSize();
|
||||
}
|
||||
} else {
|
||||
@@ -203,15 +201,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
bool isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
this._deliveryAddresses = isFromPackages
|
||||
? await addressModel.getDeliveryAddresses(_carton.userID)
|
||||
: await addressModel.getDeliveryAddresses(_carton.receiverID);
|
||||
}
|
||||
|
||||
_getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
@@ -237,7 +226,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
bool isMixBox = _selectedCartonType == carton_mix_box;
|
||||
|
||||
final shipmentBox = DisplayText(
|
||||
@@ -603,7 +592,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
isFromCargos
|
||||
isFromCartons
|
||||
? Container(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Row(
|
||||
@@ -646,8 +635,14 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
builder: (context) =>
|
||||
DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses:
|
||||
_deliveryAddresses)),
|
||||
user: isFromPackages
|
||||
? User(
|
||||
id: _carton.userID,
|
||||
name: _carton.userName)
|
||||
: User(
|
||||
id: _carton.receiverID,
|
||||
name: _carton
|
||||
.receiverName))),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
@@ -658,7 +653,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
isFromPackages || isFromCargos
|
||||
isFromPackages || isFromCartons
|
||||
? _isNew
|
||||
? createBtn
|
||||
: saveBtn
|
||||
@@ -679,7 +674,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
if (isFromPackages) {
|
||||
_loadPackages();
|
||||
c.value.packages = _carton.packages;
|
||||
@@ -812,7 +807,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
_addCarton() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
@@ -824,12 +819,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (consignee == null && isFromCargos) {
|
||||
if (consignee == null && isFromCartons) {
|
||||
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null && isFromCargos) {
|
||||
if (sender == null && isFromCartons) {
|
||||
showMsgDialog(context, "Error", "Please select sender's FCS ID");
|
||||
return;
|
||||
}
|
||||
@@ -849,7 +844,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.receiverFCSID = consignee?.fcsID;
|
||||
carton.receiverName = consignee?.name;
|
||||
@@ -881,7 +876,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_cartons.add(_carton);
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
_cartonsForCargos.add(_carton);
|
||||
}
|
||||
|
||||
@@ -943,7 +938,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
_save() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cartons;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
|
||||
@@ -88,7 +88,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box.cartonType == carton_from_packages;
|
||||
isSmallBag = _box.cartonType == carton_small_bag;
|
||||
isFromCartons = _box.cartonType == carton_from_cargos;
|
||||
isFromCartons = _box.cartonType == carton_from_cartons;
|
||||
|
||||
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
|
||||
_box.status == carton_packed_status;
|
||||
@@ -410,7 +410,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
widget.box.mixCartons=_box.mixCartons;
|
||||
widget.box.mixCartons = _box.mixCartons;
|
||||
bool updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
|
||||
|
||||
@@ -78,7 +78,7 @@ class CartonListRow extends StatelessWidget {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
"${box.actualWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
"${box.cartonWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
@@ -9,17 +9,20 @@ import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
List<Carton> _boxes = [];
|
||||
List<Carton> cartons = [];
|
||||
PaginatorListener cartonsByFilter;
|
||||
|
||||
final log = Logger('CartonModel');
|
||||
List<Carton> get boxes =>
|
||||
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
|
||||
|
||||
Paginator _delivered;
|
||||
int _selectedIndex = 1;
|
||||
int _selectedIndexFilter = 1;
|
||||
bool isLoading = false;
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
@@ -60,13 +63,13 @@ class CartonModel extends BaseModel {
|
||||
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
// carton_from_cargos,
|
||||
carton_from_cartons,
|
||||
carton_mix_box
|
||||
];
|
||||
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
|
||||
List<String> cartonTypesInfo = [
|
||||
carton_from_packages,
|
||||
carton_from_cargos,
|
||||
carton_from_cartons,
|
||||
carton_mix_box,
|
||||
carton_from_shipments,
|
||||
carton_small_bag
|
||||
@@ -77,18 +80,45 @@ class CartonModel extends BaseModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get selectedIndex => _selectedIndex;
|
||||
set selectedIndexFilter(int index) {
|
||||
_selectedIndexFilter = index;
|
||||
_loadCartonsByFilter(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
initData() {
|
||||
get selectedIndex => _selectedIndex;
|
||||
get selectedIndexFilter => _selectedIndexFilter;
|
||||
|
||||
initData() async {
|
||||
_selectedIndex = 1;
|
||||
_selectedIndexFilter = 1;
|
||||
_loadBoxes();
|
||||
_loadCartonForMixBox();
|
||||
|
||||
if (_delivered != null) _delivered.close();
|
||||
_delivered = _getDelivered();
|
||||
_delivered.load();
|
||||
}
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null || !user.hasCarton()) {
|
||||
_initData();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initData() async {
|
||||
logout();
|
||||
_selectedIndexFilter = 1;
|
||||
cartonsByFilter = PaginatorListener<Carton>(
|
||||
(data, id) => Carton.fromMap(data, id), onChange: () {
|
||||
notifyListeners();
|
||||
}, rowPerLoad: 30, insertNewByListener: true);
|
||||
|
||||
_loadCartonsByFilter(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
}
|
||||
|
||||
Future<void> _loadBoxes() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
@@ -116,30 +146,27 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadCartonForMixBox() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
if (cartonListener != null) cartonListener.cancel();
|
||||
cartons = [];
|
||||
Future<void> _loadCartonsByFilter(String orderName) async {
|
||||
if (user == null || !user.hasCarton()) return null;
|
||||
String path = "/$cartons_collection";
|
||||
|
||||
try {
|
||||
cartonListener = Firestore.instance
|
||||
Query listenerQuery = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cargos])
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("user_name")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
cartons.clear();
|
||||
cartons = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
.orderBy(orderName, descending: true);
|
||||
|
||||
notifyListeners();
|
||||
});
|
||||
Query pageQuery = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.orderBy(orderName, descending: true);
|
||||
|
||||
cartonsByFilter.refresh(
|
||||
listeningQuery: listenerQuery, pageQuery: pageQuery);
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
@@ -184,8 +211,8 @@ class CartonModel extends BaseModel {
|
||||
if (listener != null) await listener.cancel();
|
||||
if (cartonListener != null) await cartonListener.cancel();
|
||||
if (_delivered != null) _delivered.close();
|
||||
if (cartonsByFilter != null) cartonsByFilter.close();
|
||||
_boxes = [];
|
||||
cartons = [];
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
@@ -261,5 +288,4 @@ class CartonModel extends BaseModel {
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,11 +46,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
Carton _carton;
|
||||
bool _isLoading = false;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
List<CargoType> _cargoTypes = [];
|
||||
CartonSize selectedCatonSize;
|
||||
bool isFromPackages;
|
||||
bool isFromCargos;
|
||||
bool isFromCartons;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -61,8 +60,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
_load() {
|
||||
_carton = widget.carton;
|
||||
isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
isFromCargos = _carton.cartonType == carton_from_cargos;
|
||||
_getDeliverAddresses();
|
||||
isFromCartons = _carton.cartonType == carton_from_cartons;
|
||||
|
||||
if (widget.isNew) {
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
@@ -77,18 +76,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
var deliveryAddresses = isFromPackages
|
||||
? await addressModel.getDeliveryAddresses(_carton.userID)
|
||||
: await addressModel.getDeliveryAddresses(_carton.receiverID);
|
||||
setState(() {
|
||||
this._deliveryAddresses = deliveryAddresses;
|
||||
});
|
||||
}
|
||||
|
||||
_getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
@@ -205,9 +192,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses: this._deliveryAddresses,
|
||||
user: widget.consignee,
|
||||
onAdded: () => _getDeliverAddresses(),
|
||||
user: isFromPackages
|
||||
? User(
|
||||
id: _carton.userID,
|
||||
name: _carton.userName)
|
||||
: User(
|
||||
id: _carton.receiverID,
|
||||
name: _carton.receiverName),
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
@@ -342,7 +333,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
carton.receiverID = _carton.receiverID;
|
||||
carton.receiverFCSID = _carton.receiverFCSID;
|
||||
carton.receiverName = _carton.receiverName;
|
||||
|
||||
@@ -8,7 +8,11 @@ import 'carton_search.dart';
|
||||
class CartonListRow extends StatefulWidget {
|
||||
final CallbackCartonSelect callbackCartonSelect;
|
||||
final Carton carton;
|
||||
const CartonListRow({this.carton, this.callbackCartonSelect});
|
||||
|
||||
// const CartonListRow({this.carton, this.callbackCartonSelect});
|
||||
CartonListRow(
|
||||
{Key key, this.carton, this.callbackCartonSelect})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_CartonListRowState createState() => _CartonListRowState();
|
||||
@@ -82,7 +86,7 @@ class _CartonListRowState extends State<CartonListRow> {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
"${_carton.actualWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
"${_carton.cartonWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/barcode_scanner.dart';
|
||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/popupmenu.dart';
|
||||
import 'package:fcs/pagination/paginator_listview.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -42,12 +48,32 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
|
||||
@override
|
||||
List<Widget> buildActions(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
final popupMenu =
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.weight",
|
||||
selected: boxModel.selectedIndexFilter == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.name",
|
||||
selected: boxModel.selectedIndexFilter == 2)
|
||||
],
|
||||
popupMenuCallback: (p) => setState(() {
|
||||
boxModel.selectedIndexFilter = p.id;
|
||||
}));
|
||||
});
|
||||
|
||||
return [
|
||||
IconButton(
|
||||
icon: Icon(MaterialCommunityIcons.barcode_scan,
|
||||
size: 30, color: Colors.white),
|
||||
onPressed: () => _scan(context),
|
||||
),
|
||||
popupMenu,
|
||||
IconButton(
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () => query = '',
|
||||
@@ -85,6 +111,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
child: ListView(
|
||||
children: snapshot.data
|
||||
.map((u) => CartonListRow(
|
||||
key: ValueKey(u.id),
|
||||
carton: u,
|
||||
callbackCartonSelect: callbackCartonSelect,
|
||||
))
|
||||
@@ -115,15 +142,17 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
@override
|
||||
Widget buildSuggestions(BuildContext context) {
|
||||
final cartonModel = Provider.of<CartonModel>(context);
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: ListView(
|
||||
children: cartonModel.cartons
|
||||
.map((u) => CartonListRow(
|
||||
carton: u,
|
||||
callbackCartonSelect: callbackCartonSelect,
|
||||
))
|
||||
.toList(),
|
||||
child: PaginatorListView<Carton>(
|
||||
paginatorListener: cartonModel.cartonsByFilter,
|
||||
rowBuilder: (c) => CartonListRow(
|
||||
key: ValueKey(c.id),
|
||||
carton: c,
|
||||
callbackCartonSelect: callbackCartonSelect,
|
||||
),
|
||||
color: primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
try {
|
||||
await deliveryAddressModel.createDeliveryAddress(deliveryAddress);
|
||||
Navigator.pop(context,true);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -223,6 +223,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
if (widget.user != null) {
|
||||
deliveryAddress.userID = widget.user.id;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -230,7 +233,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
try {
|
||||
await deliveryAddressModel.updateDeliveryAddress(deliveryAddress);
|
||||
Navigator.pop(context,true);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -251,8 +254,11 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
try {
|
||||
DeliveryAddressModel deliveryAddressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
if (widget.user != null) {
|
||||
_deliveryAddress.userID = widget.user.id;
|
||||
}
|
||||
await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress);
|
||||
Navigator.pop(context,true);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
@@ -91,6 +91,7 @@ class DeliveryAddressModel extends BaseModel {
|
||||
.collection('users')
|
||||
.document("$userID")
|
||||
.collection("$path")
|
||||
.orderBy("full_name")
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => DeliveryAddress.fromMap(e.data, e.documentID))
|
||||
|
||||
@@ -70,7 +70,7 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
bool canChangeDeliveryAddress =
|
||||
_package?.status == package_received_status ||
|
||||
_package?.status == package_processed_status;
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
var mainModel = Provider.of<MainModel>(context);
|
||||
|
||||
final trackingIdBox = DisplayText(
|
||||
text: _package?.trackingID ?? "",
|
||||
@@ -122,7 +122,7 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _package.deliveryAddress,
|
||||
deliveryAddresses: deliveryAddressModel.deliveryAddresses)),
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (d == null) return;
|
||||
_changeDeliverayAddress(d);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/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/defalut_delivery_address.dart';
|
||||
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
||||
@@ -81,7 +82,8 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
var mainModel = Provider.of<MainModel>(context);
|
||||
|
||||
final shipmentWeightBox = DisplayText(
|
||||
labelTextKey: "shipment.box.shipment.weight",
|
||||
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
|
||||
@@ -192,8 +194,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
deliveryAddresses:
|
||||
deliveryAddressModel.deliveryAddresses)),
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
|
||||
@@ -91,7 +91,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
final fromTimeBox = InputTime(
|
||||
labelTextKey: 'shipment.from',
|
||||
iconData: Icons.timer,
|
||||
@@ -129,9 +129,8 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddresses: deliveryAddressModel.deliveryAddresses,
|
||||
)),
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (address == null) return;
|
||||
setState(() {
|
||||
|
||||
@@ -9,34 +9,44 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
typedef OnAdded();
|
||||
|
||||
class DeliveryAddressSelection extends StatelessWidget {
|
||||
class DeliveryAddressSelection extends StatefulWidget {
|
||||
final DeliveryAddress deliveryAddress;
|
||||
final List<DeliveryAddress> deliveryAddresses;
|
||||
final User user;
|
||||
final OnAdded onAdded;
|
||||
|
||||
const DeliveryAddressSelection(
|
||||
{Key key,
|
||||
this.deliveryAddress,
|
||||
this.deliveryAddresses,
|
||||
this.user,
|
||||
this.onAdded})
|
||||
: super(key: key);
|
||||
const DeliveryAddressSelection({
|
||||
Key key,
|
||||
this.deliveryAddress,
|
||||
this.user,
|
||||
}) : super(key: key);
|
||||
|
||||
Future<List<DeliveryAddress>> _getDeliverAddresses(
|
||||
BuildContext context) async {
|
||||
@override
|
||||
_DeliveryAddressSelectionState createState() =>
|
||||
_DeliveryAddressSelectionState();
|
||||
}
|
||||
|
||||
class _DeliveryAddressSelectionState extends State<DeliveryAddressSelection> {
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_getDeliverAddresses();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
var _deliveryAddresses = await addressModel.getDeliveryAddresses(user.id);
|
||||
return _deliveryAddresses;
|
||||
var deliveryAddresses =
|
||||
await addressModel.getDeliveryAddresses(widget.user.id);
|
||||
setState(() {
|
||||
this._deliveryAddresses = deliveryAddresses;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (user != null) {}
|
||||
if (widget.user != null) {}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
@@ -52,12 +62,10 @@ class DeliveryAddressSelection extends StatelessWidget {
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () async {
|
||||
bool updated = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressEditor(
|
||||
user: user,
|
||||
)));
|
||||
if (updated && onAdded != null) {
|
||||
onAdded();
|
||||
Navigator.pop(context);
|
||||
builder: (context) =>
|
||||
DeliveryAddressEditor(user: widget.user)));
|
||||
if (updated ?? false) {
|
||||
_getDeliverAddresses();
|
||||
}
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
@@ -71,37 +79,46 @@ class DeliveryAddressSelection extends StatelessWidget {
|
||||
separatorBuilder: (c, i) => Divider(
|
||||
color: primaryColor,
|
||||
),
|
||||
itemCount: deliveryAddresses.length,
|
||||
itemCount: _deliveryAddresses.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _row(context, deliveryAddresses[index]);
|
||||
return _row(context, _deliveryAddresses[index]);
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
_row(BuildContext context, DeliveryAddress _deliveryAddress) {
|
||||
return InkWell(
|
||||
onTap: () => _select(context, _deliveryAddress),
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
return Row(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () => _select(context, _deliveryAddress),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Icon(Icons.check,
|
||||
color: deliveryAddress != null &&
|
||||
_deliveryAddress.id == deliveryAddress.id
|
||||
color: widget.deliveryAddress != null &&
|
||||
_deliveryAddress.id == widget.deliveryAddress.id
|
||||
? primaryColor
|
||||
: Colors.black26),
|
||||
),
|
||||
Expanded(
|
||||
child: DeliveryAddressRow(
|
||||
key: ValueKey(_deliveryAddress.id),
|
||||
deliveryAddress: _deliveryAddress,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: DeliveryAddressRow(
|
||||
key: ValueKey(_deliveryAddress.id),
|
||||
deliveryAddress: _deliveryAddress,
|
||||
selectionCallback: (d) => _edit(context, _deliveryAddress))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_select(BuildContext context, DeliveryAddress _deliveryAddress) {
|
||||
Navigator.pop(context, _deliveryAddress);
|
||||
}
|
||||
|
||||
_edit(BuildContext context, DeliveryAddress deliveryAddress) async {
|
||||
bool updated = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressEditor(
|
||||
user: widget.user, deliveryAddress: deliveryAddress)));
|
||||
if (updated ?? false) {
|
||||
_getDeliverAddresses();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class _DialogInputState extends State<DialogInput> {
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.number,
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: new InputDecoration(
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0))),
|
||||
|
||||
Reference in New Issue
Block a user