Files
fcs/lib/pages/box/box_list.dart

138 lines
4.3 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/box/model/box_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-07 02:33:06 +06:30
import 'box_editor.dart';
import 'box_list_row.dart';
2020-06-04 01:36:49 +06:30
class BoxList extends StatefulWidget {
@override
_BoxListState createState() => _BoxListState();
}
class _BoxListState extends State<BoxList> {
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) {
Provider.of<BoxModel>(context, listen: false).loadMore();
}
});
Provider.of<BoxModel>(context, listen: false).initData();
2020-06-04 01:36:49 +06:30
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
2020-10-15 17:33:43 +06:30
var boxModel = Provider.of<BoxModel>(context);
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,
),
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15),
shrinkWrap: true,
itemCount: boxModel.boxes.length,
itemBuilder: (BuildContext context, int index) {
return BoxListRow(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(),
],
),
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,
CupertinoPageRoute(builder: (context) => BoxEditor()),
2020-06-04 01:36:49 +06:30
);
}
}