add pagination for invoice and update ui for material 3
This commit is contained in:
@@ -21,30 +21,21 @@ class PackageModel extends BaseModel {
|
||||
PaginatorListener<Package>? activePackages;
|
||||
|
||||
bool isLoading = false;
|
||||
int _menuSelectedIndex = 1;
|
||||
int selectedIndex = 1;
|
||||
|
||||
set menuSelectedIndex(int index) {
|
||||
_menuSelectedIndex = index;
|
||||
|
||||
_loadPaginationPackages(_menuSelectedIndex == 2);
|
||||
_loadPaginationCustomerPackages(_menuSelectedIndex == 2);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int get menuSelectedIndex => _menuSelectedIndex;
|
||||
|
||||
void privilegeChanged() {
|
||||
if (user != null) {
|
||||
_initData();
|
||||
initData(int index, bool isCustomer) {
|
||||
selectedIndex = index;
|
||||
if (isCustomer) {
|
||||
_loadPaginationCustomerPackages(selectedIndex == 2);
|
||||
} else {
|
||||
_loadPaginationPackages(selectedIndex == 2);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initData() async {
|
||||
_menuSelectedIndex = 1;
|
||||
_loadPaginationPackages(_menuSelectedIndex == 2);
|
||||
_loadPaginationCustomerPackages(_menuSelectedIndex == 2);
|
||||
_loadPaginationActivePackages();
|
||||
void privilegeChanged() {
|
||||
if (user != null) {
|
||||
_loadPaginationActivePackages();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -54,6 +45,16 @@ 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);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
_loadPaginationPackages(bool isDelivered) {
|
||||
if (user == null) return;
|
||||
if (!((user!.hasPackages() ||
|
||||
@@ -78,7 +79,6 @@ class PackageModel extends BaseModel {
|
||||
_loadPaginationCustomerPackages(bool isDelivered) {
|
||||
if (user == null) return;
|
||||
String path = "/$packages_collection";
|
||||
|
||||
Query col = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_delivered", isEqualTo: isDelivered)
|
||||
|
||||
@@ -23,12 +23,24 @@ class PackageList extends StatefulWidget {
|
||||
|
||||
class _PackageListState extends State<PackageList> {
|
||||
bool _isLoading = false;
|
||||
int _selectedIndex = 1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() {
|
||||
var model = context.read<PackageModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.initData(_selectedIndex, widget.forCustomer);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var packageModel = Provider.of<PackageModel>(context);
|
||||
@@ -37,20 +49,24 @@ class _PackageListState extends State<PackageList> {
|
||||
: packageModel.packages;
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "package.popupmenu.active",
|
||||
selected: packageModel.menuSelectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "package.popupmenu.delivered",
|
||||
selected: packageModel.menuSelectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) => this.setState(() {
|
||||
packageModel.menuSelectedIndex = p.id;
|
||||
}),
|
||||
);
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "package.popupmenu.active",
|
||||
selected: packageModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "package.popupmenu.delivered",
|
||||
selected: packageModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
this.setState(() {
|
||||
_selectedIndex = p.id;
|
||||
});
|
||||
context
|
||||
.read<PackageModel>()
|
||||
.onChanged(_selectedIndex, widget.forCustomer);
|
||||
});
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
|
||||
Reference in New Issue
Block a user