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

101 lines
2.9 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';
2024-01-24 16:54:08 +06:30
import '../../domain/entities/carton.dart';
import '../../pagination/paginator_listview.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;
2024-01-24 16:54:08 +06:30
int _selectedIndex = 1;
2020-06-04 01:36:49 +06:30
@override
void initState() {
super.initState();
2024-01-24 16:54:08 +06:30
_init();
2020-06-04 01:36:49 +06:30
}
2024-01-24 16:54:08 +06:30
_init() {
var model = context.read<CartonModel>();
_selectedIndex = model.selectedIndex;
model.loadPaginationBoxes(_selectedIndex);
if (mounted) {
setState(() {});
}
2020-06-04 01:36:49 +06:30
}
@override
Widget build(BuildContext context) {
2020-10-18 02:38:46 +06:30
var boxModel = Provider.of<CartonModel>(context);
2024-01-24 16:54:08 +06:30
2020-10-15 17:33:43 +06:30
final popupMenu = LocalPopupMenuButton(
2024-01-24 16:54:08 +06:30
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);
});
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),
2020-10-22 04:14:53 +06:30
actions: <Widget>[popupMenu],
2020-10-15 17:33:43 +06:30
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
_newBox();
},
icon: Icon(Icons.add),
label: LocalText(context, "boxes.new", color: Colors.white),
backgroundColor: primaryColor,
),
2024-01-24 16:54:08 +06:30
body: PaginatorListView<Carton>(
paginatorListener: boxModel.getBoxes!,
rowBuilder: (p) => CartonListRow(box: p),
color: primaryColor),
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
);
}
}