add pagination for pages
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/carton.dart';
|
||||
import '../../pagination/paginator_listview.dart';
|
||||
import 'delivery_list_row.dart';
|
||||
import 'model/delivery_model.dart';
|
||||
|
||||
@@ -17,97 +19,62 @@ class DeliverList extends StatefulWidget {
|
||||
|
||||
class _DeliverListState extends State<DeliverList> {
|
||||
bool _isLoading = false;
|
||||
var _controller = ScrollController();
|
||||
int _selectedIndex = 1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.addListener(() async {
|
||||
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
|
||||
Provider.of<DeliveryModel>(context, listen: false).loadMore();
|
||||
}
|
||||
});
|
||||
Provider.of<DeliveryModel>(context, listen: false).initData();
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_init() {
|
||||
var model = context.read<DeliveryModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.loadPaginationCartons(_selectedIndex);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var deliveryModel = Provider.of<DeliveryModel>(context);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "delivery.popupmenu.active",
|
||||
selected: deliveryModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "delivery.popupmenu.delivered",
|
||||
selected: deliveryModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) => this.setState(() {
|
||||
deliveryModel.selectedIndex = p.id;
|
||||
}),
|
||||
);
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "delivery.popupmenu.active",
|
||||
selected: deliveryModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "delivery.popupmenu.delivered",
|
||||
selected: deliveryModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
setState(() {
|
||||
_selectedIndex = p.id;
|
||||
});
|
||||
context.read<DeliveryModel>().onChanged(_selectedIndex);
|
||||
});
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(context, "delivery",
|
||||
color: Colors.white, fontSize: 20),
|
||||
actions: <Widget>[popupMenu],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
child: new ListView.separated(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
height: 1,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: deliveryModel.cartons.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return DeliveryListRow(
|
||||
key: ValueKey(deliveryModel.cartons[index].id),
|
||||
box: deliveryModel.cartons[index]);
|
||||
}),
|
||||
onRefresh: () => deliveryModel.refresh(),
|
||||
),
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
deliveryModel.isLoading
|
||||
? Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
color: primaryColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Loading...",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(context, "delivery",
|
||||
color: Colors.white, fontSize: 20),
|
||||
actions: <Widget>[popupMenu],
|
||||
),
|
||||
body: PaginatorListView<Carton>(
|
||||
paginatorListener: deliveryModel.getCartons!,
|
||||
rowBuilder: (p) => DeliveryListRow(box: p),
|
||||
color: primaryColor)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user