add pagination for pages

This commit is contained in:
tzw
2024-01-24 16:54:08 +06:30
parent 4b9dc7bdc2
commit 0dc32067b8
34 changed files with 399 additions and 2249 deletions

View File

@@ -1,5 +1,4 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class BoxRow extends StatelessWidget {

View File

@@ -1,149 +0,0 @@
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/shipment/model/shipment_model.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/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
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;
var _controller = ScrollController();
bool _forCustomer = true;
@override
void initState() {
super.initState();
_forCustomer = widget.forCustomer;
_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(widget.forCustomer);
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
ShipmentModel shipmentModel = Provider.of<ShipmentModel>(context);
final popupMenu = LocalPopupMenuButton(
popmenus: _forCustomer
? [
LocalPopupMenu(
id: 1, textKey: "shipment.popupmenu.active", selected: true),
LocalPopupMenu(id: 2, textKey: "shipment.popupmenu.delivered"),
]
: [
LocalPopupMenu(
id: 1, textKey: "shipment.popupmenu.active", selected: true),
LocalPopupMenu(id: 2, textKey: "shipment.popupmenu.delivered"),
LocalPopupMenu(id: 3, textKey: "shipment.popupmenu.mypickup"),
],
popupMenuCallback: (p) => this.setState(() {
shipmentModel.menuSelectedIndex = p.id;
if (p.id == 3) {
Provider.of<ShipmentModel>(context, listen: false)
.initData(widget.forCustomer, myPickup: true);
} else {
Provider.of<ShipmentModel>(context, listen: false)
.initData(widget.forCustomer, myPickup: false);
}
}),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: LocalText(context, "shipment",
fontSize: 18, color: Colors.white),
actions: <Widget>[popupMenu],
),
floatingActionButton: widget.forCustomer
? 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.grey,
height: 1,
),
scrollDirection: Axis.vertical,
itemCount: shipmentModel.shipments.length,
itemBuilder: (BuildContext context, int index) {
return ShipmentListRow(
key: ValueKey(shipmentModel.shipments[index].id),
shipment: shipmentModel.shipments[index],
isCustomer: widget.forCustomer,
);
}),
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(),
],
),
),
),
);
}
_newPickup() {
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => ShipmentEditor()));
}
}

View File

@@ -1,98 +0,0 @@
import 'package:fcs/domain/entities/shipment.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
import '../main/util.dart';
import 'shipment_info.dart';
class ShipmentListRow extends StatelessWidget {
final Shipment? shipment;
final bool? isCustomer;
const ShipmentListRow({Key? key, this.shipment, this.isCustomer})
: super(key: key);
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => ShipmentInfo(
shipment: shipment,
isCustomer: isCustomer,
)));
},
child: Container(
padding: EdgeInsets.only(left: 15, right: 15),
child: Row(
children: <Widget>[
Expanded(
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: new Row(
children: <Widget>[
Padding(
padding: EdgeInsets.all(5.0),
child: Icon(
SimpleLineIcons.direction,
color: primaryColor,
)),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
shipment!.shipmentNumber ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
),
// Padding(
// padding: const EdgeInsets.only(left: 10.0, top: 3),
// child: new Text(
// "Last ${shipment.last ?? 0} days",
// style: new TextStyle(
// fontSize: 15.0, color: Colors.grey),
// ),
// )
],
),
),
],
),
),
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0),
child: getStatus(shipment!.status ?? ""),
),
// Padding(
// padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
// child: Row(
// children: <Widget>[
// new Text(
// "(${pickUp.totalWeight ?? "0"}) lb ",
// style:
// new TextStyle(fontSize: 15.0, color: Colors.grey),
// ),
// new Text(
// "(${pickUp.totalCount ?? "0"}) cartons ",
// style:
// new TextStyle(fontSize: 15.0, color: Colors.grey),
// ),
// ],
// ),
// ),
],
)
],
),
),
);
}
}