Files
fcs/lib/pages/carton/carton_list.dart

140 lines
4.4 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-10-18 02:38:46 +06:30
import 'package:fcs/pages/carton/model/carton_model.dart';
2020-10-15 17:33:43 +06:30
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
import 'package:fcs/pages/widgets/local_popupmenu.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-12 03:34:05 +06:30
import 'package:flutter/cupertino.dart';
2020-06-04 01:36:49 +06:30
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
2020-10-19 05:13:49 +06:30
import 'carton_editor.dart';
import 'carton_list_row.dart';
2020-06-04 01:36:49 +06:30
2020-10-19 05:13:49 +06:30
class CartonList extends StatefulWidget {
2020-06-04 01:36:49 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonListState createState() => _CartonListState();
2020-06-04 01:36:49 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonListState extends State<CartonList> {
2020-06-04 01:36:49 +06:30
bool _isLoading = false;
2020-10-16 17:57:58 +06:30
var _controller = ScrollController();
2020-06-04 01:36:49 +06:30
@override
void initState() {
super.initState();
2020-10-16 17:57:58 +06:30
_controller.addListener(() async {
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
2020-10-18 02:38:46 +06:30
Provider.of<CartonModel>(context, listen: false).loadMore();
2020-10-16 17:57:58 +06:30
}
});
2020-10-18 02:38:46 +06:30
Provider.of<CartonModel>(context, listen: false).initData();
2020-06-04 01:36:49 +06:30
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
2020-10-18 02:38:46 +06:30
var boxModel = Provider.of<CartonModel>(context);
2020-10-15 17:33:43 +06:30
final popupMenu = LocalPopupMenuButton(
popmenus: [
2020-10-16 17:57:58 +06:30
LocalPopupMenu(
id: 1,
textKey: "box.popupmenu.active",
selected: boxModel.selectedIndex == 1),
LocalPopupMenu(
id: 2,
textKey: "box.popupmenu.delivered",
selected: boxModel.selectedIndex == 2)
2020-10-15 17:33:43 +06:30
],
popupMenuCallback: (p) => this.setState(() {
2020-10-16 17:57:58 +06:30
boxModel.selectedIndex = p.id;
2020-10-15 17:33:43 +06:30
}),
);
2020-06-04 01:36:49 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: DefaultTabController(
length: 2,
child: Scaffold(
2020-10-15 17:33:43 +06:30
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: LocalText(context, "boxes.name",
color: Colors.white, fontSize: 20),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
2020-06-04 01:36:49 +06:30
),
2020-10-15 17:33:43 +06:30
iconSize: 30, onPressed: () {},
// onPressed: () => showPlacesSearch(context),
2020-06-04 01:36:49 +06:30
),
2020-10-15 17:33:43 +06:30
popupMenu
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
_newBox();
},
icon: Icon(Icons.add),
label: LocalText(context, "boxes.new", color: Colors.white),
backgroundColor: primaryColor,
),
2020-10-16 17:57:58 +06:30
body: Column(
children: [
Expanded(
child: RefreshIndicator(
child: new ListView.separated(
physics: AlwaysScrollableScrollPhysics(),
controller: _controller,
separatorBuilder: (context, index) => Divider(
color: Colors.black,
2020-10-19 05:13:49 +06:30
height: 1,
2020-10-16 17:57:58 +06:30
),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: boxModel.boxes.length,
itemBuilder: (BuildContext context, int index) {
2020-10-19 05:13:49 +06:30
return CartonListRow(
key: ValueKey(boxModel.boxes[index].id),
box: boxModel.boxes[index]);
2020-10-16 17:57:58 +06:30
}),
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(),
],
),
2020-06-04 01:36:49 +06:30
),
2020-10-15 17:33:43 +06:30
),
2020-06-04 01:36:49 +06:30
);
}
2020-10-15 17:33:43 +06:30
_newBox() {
Navigator.push(
context,
2020-10-19 05:13:49 +06:30
CupertinoPageRoute(builder: (context) => CartonEditor()),
2020-06-04 01:36:49 +06:30
);
}
}