add pagination for pages
This commit is contained in:
@@ -8,6 +8,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 'carton_editor.dart';
|
||||
import 'carton_list_row.dart';
|
||||
|
||||
@@ -18,42 +20,44 @@ class CartonList extends StatefulWidget {
|
||||
|
||||
class _CartonListState extends State<CartonList> {
|
||||
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<CartonModel>(context, listen: false).loadMore();
|
||||
}
|
||||
});
|
||||
Provider.of<CartonModel>(context, listen: false).initData();
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_init() {
|
||||
var model = context.read<CartonModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.loadPaginationBoxes(_selectedIndex);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.popupmenu.active",
|
||||
selected: boxModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.popupmenu.delivered",
|
||||
selected: boxModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) => this.setState(() {
|
||||
boxModel.selectedIndex = p.id;
|
||||
}),
|
||||
);
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.popupmenu.active",
|
||||
selected: boxModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.popupmenu.delivered",
|
||||
selected: boxModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
setState(() {
|
||||
_selectedIndex = p.id;
|
||||
});
|
||||
context.read<CartonModel>().onChanged(_selectedIndex);
|
||||
});
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: DefaultTabController(
|
||||
@@ -78,43 +82,10 @@ class _CartonListState extends State<CartonList> {
|
||||
label: LocalText(context, "boxes.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
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: boxModel.boxes.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return CartonListRow(
|
||||
key: ValueKey(boxModel.boxes[index].id),
|
||||
box: boxModel.boxes[index]);
|
||||
}),
|
||||
onRefresh: () => boxModel.refresh(),
|
||||
),
|
||||
),
|
||||
boxModel.isLoading
|
||||
? Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
color: primaryColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Loading...",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
body: PaginatorListView<Carton>(
|
||||
paginatorListener: boxModel.getBoxes!,
|
||||
rowBuilder: (p) => CartonListRow(box: p),
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user