update carton and cargo type
This commit is contained in:
@@ -23,17 +23,20 @@ class PackageModel extends BaseModel {
|
||||
PaginatorListener<Package>? activePackages;
|
||||
|
||||
bool isLoading = false;
|
||||
int selectedIndex = 1;
|
||||
int selectedIndexForCustomer = 1;
|
||||
int selectedIndex = 0;
|
||||
|
||||
initData(int index, bool isCustomer) {
|
||||
selectedIndex = index;
|
||||
if (isCustomer) {
|
||||
_loadPaginationCustomerPackages(selectedIndex == 2);
|
||||
} else {
|
||||
_loadPaginationPackages(selectedIndex == 2);
|
||||
}
|
||||
initDataForCustomer(int index) {
|
||||
selectedIndexForCustomer = index;
|
||||
_loadPaginationCustomerPackages(selectedIndexForCustomer == 2);
|
||||
}
|
||||
|
||||
initData(int index) {
|
||||
selectedIndex = index;
|
||||
_loadPaginationPackages(selectedIndex);
|
||||
}
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null) {
|
||||
_loadPaginationActivePackages();
|
||||
@@ -47,30 +50,57 @@ class PackageModel extends BaseModel {
|
||||
if (activePackages != null) activePackages!.close();
|
||||
}
|
||||
|
||||
onChanged(int index, bool isCustomer) {
|
||||
selectedIndex = index;
|
||||
if (isCustomer) {
|
||||
_loadPaginationCustomerPackages(selectedIndex == 2);
|
||||
} else {
|
||||
_loadPaginationPackages(selectedIndex == 2);
|
||||
}
|
||||
onChangedForCustomer(int index) {
|
||||
selectedIndexForCustomer = index;
|
||||
_loadPaginationCustomerPackages(selectedIndexForCustomer == 2);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
_loadPaginationPackages(bool isDelivered) {
|
||||
_loadPaginationPackages(int index) {
|
||||
if (user == null) return;
|
||||
if (!((user!.hasPackages() ||
|
||||
user!.hasReceiving() ||
|
||||
user!.hasProcessing()))) return;
|
||||
user!.hasProcessing()))) {
|
||||
return;
|
||||
}
|
||||
String path = "/$packages_collection";
|
||||
|
||||
Query col = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_delivered", isEqualTo: isDelivered);
|
||||
Query pageQuery = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_delivered", isEqualTo: isDelivered)
|
||||
.orderBy("update_time", descending: true);
|
||||
Query col = FirebaseFirestore.instance.collection(path);
|
||||
Query pageQuery = FirebaseFirestore.instance.collection(path);
|
||||
|
||||
// received status
|
||||
if (index == 1) {
|
||||
col = col.where("status", isEqualTo: package_received_status);
|
||||
pageQuery = pageQuery.where("status", isEqualTo: package_received_status);
|
||||
}
|
||||
|
||||
// processed status
|
||||
if (index == 2) {
|
||||
col = col.where("status", isEqualTo: package_processed_status);
|
||||
pageQuery =
|
||||
pageQuery.where("status", isEqualTo: package_processed_status);
|
||||
}
|
||||
|
||||
// packed status
|
||||
if (index == 3) {
|
||||
col = col.where("status", isEqualTo: package_packed_status);
|
||||
pageQuery = pageQuery.where("status", isEqualTo: package_packed_status);
|
||||
}
|
||||
|
||||
// shipped status
|
||||
if (index == 4) {
|
||||
col = col.where("status", isEqualTo: package_shipped_status);
|
||||
pageQuery = pageQuery.where("status", isEqualTo: package_shipped_status);
|
||||
}
|
||||
|
||||
// delivered status
|
||||
if (index == 5) {
|
||||
col = col.where("status", isEqualTo: package_delivered_status);
|
||||
pageQuery =
|
||||
pageQuery.where("status", isEqualTo: package_delivered_status);
|
||||
}
|
||||
|
||||
pageQuery = pageQuery.orderBy("update_time", descending: true);
|
||||
|
||||
packages?.close();
|
||||
packages = PaginatorListener<Package>(
|
||||
@@ -78,6 +108,12 @@ class PackageModel extends BaseModel {
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
onChanged(int index) {
|
||||
selectedIndex = index;
|
||||
_loadPaginationPackages(index);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
_loadPaginationCustomerPackages(bool isDelivered) {
|
||||
if (user == null) return;
|
||||
String path = "/$packages_collection";
|
||||
@@ -102,7 +138,9 @@ class PackageModel extends BaseModel {
|
||||
if (user == null) return;
|
||||
if (!((user!.hasPackages() ||
|
||||
user!.hasReceiving() ||
|
||||
user!.hasProcessing()))) return;
|
||||
user!.hasProcessing()))) {
|
||||
return;
|
||||
}
|
||||
String path = "/$packages_collection";
|
||||
|
||||
Query col = FirebaseFirestore.instance
|
||||
@@ -142,7 +180,7 @@ class PackageModel extends BaseModel {
|
||||
String path = "/$packages_collection";
|
||||
try {
|
||||
var snaps = await FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.collection(path)
|
||||
.where("tracking_id", isEqualTo: trackingID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.get(const GetOptions(source: Source.server));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
@@ -16,14 +18,15 @@ import 'package:provider/provider.dart';
|
||||
class PackageList extends StatefulWidget {
|
||||
final bool forCustomer;
|
||||
|
||||
const PackageList({Key? key, this.forCustomer = true}) : super(key: key);
|
||||
const PackageList({super.key, this.forCustomer = true});
|
||||
@override
|
||||
_PackageListState createState() => _PackageListState();
|
||||
}
|
||||
|
||||
class _PackageListState extends State<PackageList> {
|
||||
bool _isLoading = false;
|
||||
int _selectedIndex = 1;
|
||||
bool isLoading = false;
|
||||
int _selectedIndexForCustomer = 1;
|
||||
int _selectedIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -33,8 +36,13 @@ class _PackageListState extends State<PackageList> {
|
||||
|
||||
_init() {
|
||||
var model = context.read<PackageModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.initData(_selectedIndex, widget.forCustomer);
|
||||
if (widget.forCustomer) {
|
||||
_selectedIndexForCustomer = model.selectedIndexForCustomer;
|
||||
model.initDataForCustomer(_selectedIndexForCustomer);
|
||||
} else {
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.initData(_selectedIndex);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
@@ -53,23 +61,23 @@ class _PackageListState extends State<PackageList> {
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "package.popupmenu.active",
|
||||
selected: packageModel.selectedIndex == 1),
|
||||
selected: packageModel.selectedIndexForCustomer == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "package.popupmenu.delivered",
|
||||
selected: packageModel.selectedIndex == 2)
|
||||
selected: packageModel.selectedIndexForCustomer == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
this.setState(() {
|
||||
_selectedIndex = p.id;
|
||||
setState(() {
|
||||
_selectedIndexForCustomer = p.id;
|
||||
});
|
||||
context
|
||||
.read<PackageModel>()
|
||||
.onChanged(_selectedIndex, widget.forCustomer);
|
||||
.onChangedForCustomer(_selectedIndexForCustomer);
|
||||
});
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
inAsyncCall: isLoading,
|
||||
child: Scaffold(
|
||||
appBar: LocalAppBar(
|
||||
labelKey: 'package.title',
|
||||
@@ -84,7 +92,7 @@ class _PackageListState extends State<PackageList> {
|
||||
iconSize: 30,
|
||||
onPressed: () => searchPackage(context,
|
||||
callbackPackageSelect: _searchCallback)),
|
||||
popupMenu
|
||||
widget.forCustomer ? popupMenu : _menuFilteringWidget(context)
|
||||
],
|
||||
),
|
||||
body: PaginatorListView<Package>(
|
||||
@@ -98,11 +106,77 @@ class _PackageListState extends State<PackageList> {
|
||||
|
||||
_searchCallback(Package package) async {
|
||||
var packageModel = Provider.of<PackageModel>(context, listen: false);
|
||||
Package? _package = await packageModel.getPackage(package.id!);
|
||||
if (_package == null) return;
|
||||
Package? package0 = await packageModel.getPackage(package.id!);
|
||||
if (package0 == null) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => PackageInfo(package: _package)),
|
||||
CupertinoPageRoute(builder: (context) => PackageInfo(package: package0)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _menuFilteringWidget(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: PopupMenuButton<LocalPopupMenu>(
|
||||
elevation: 3.2,
|
||||
tooltip: '',
|
||||
onSelected: (choice) async {
|
||||
setState(() {
|
||||
_selectedIndex = choice.id;
|
||||
});
|
||||
|
||||
await context.read<PackageModel>().onChanged(choice.id);
|
||||
},
|
||||
icon: SizedBox(
|
||||
width: 30,
|
||||
height: 30,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
const Icon(
|
||||
Icons.filter_list,
|
||||
color: Colors.white,
|
||||
),
|
||||
_selectedIndex != 0
|
||||
? Positioned(
|
||||
bottom: 15,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return packageFiteringMenu.map((LocalPopupMenu choice) {
|
||||
return PopupMenuItem<LocalPopupMenu>(
|
||||
value: choice,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: Text("${choice.text}",
|
||||
style: TextStyle(color: Colors.black))),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
_selectedIndex == choice.id
|
||||
? const Icon(
|
||||
Icons.check,
|
||||
color: Colors.grey,
|
||||
)
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,20 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
typedef CallbackPackageSelect(Package package);
|
||||
typedef CallbackPackageSelect = Function(Package package);
|
||||
|
||||
class PackageListRow extends StatelessWidget {
|
||||
final bool isCustomer;
|
||||
final Package package;
|
||||
final CallbackPackageSelect? callbackPackageSelect;
|
||||
final double dotSize = 15.0;
|
||||
final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
|
||||
final DateFormat dateFormat = DateFormat("dd MMM yyyy");
|
||||
|
||||
PackageListRow(
|
||||
{Key? key,
|
||||
{super.key,
|
||||
required this.package,
|
||||
this.callbackPackageSelect,
|
||||
this.isCustomer = false})
|
||||
: super(key: key);
|
||||
this.isCustomer = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -44,30 +43,30 @@ class PackageListRow extends StatelessWidget {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: new Padding(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 13),
|
||||
child: new Row(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(Octicons.package, color: primaryColor),
|
||||
new Expanded(
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: new Column(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
Text(
|
||||
package.id == null ? '' : package.trackingID!,
|
||||
style: new TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: new Text(
|
||||
child: Text(
|
||||
package.market == null
|
||||
? ''
|
||||
: package.market!,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
style: TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -88,12 +87,11 @@ class PackageListRow extends StatelessWidget {
|
||||
fontWeight: FontWeight.bold)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: new Text(
|
||||
child: Text(
|
||||
package.currentStatusDate != null
|
||||
? dateFormat.format(package.currentStatusDate!)
|
||||
: '',
|
||||
style:
|
||||
new TextStyle(fontSize: 14.0, color: Colors.grey),
|
||||
style: TextStyle(fontSize: 14.0, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user