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

97 lines
2.7 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';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.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,
2024-01-31 17:14:14 +06:30
text: "Processing",
2024-01-24 16:54:08 +06:30
selected: boxModel.selectedIndex == 1),
LocalPopupMenu(
id: 2,
2024-01-31 17:14:14 +06:30
text: "Shipped",
selected: boxModel.selectedIndex == 2),
LocalPopupMenu(
id: 3,
text: "Arrived",
selected: boxModel.selectedIndex == 2),
LocalPopupMenu(
id: 4,
text: "Invoiced",
2024-01-24 16:54:08 +06:30
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,
2024-01-25 17:40:35 +06:30
child: Scaffold(
appBar: LocalAppBar(labelKey: "boxes.name", actions: [popupMenu]),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
_newBox();
},
icon: Icon(Icons.add),
label: LocalText(context, "boxes.new", color: Colors.white),
backgroundColor: primaryColor,
2020-06-04 01:36:49 +06:30
),
2024-01-25 17:40:35 +06:30
body: PaginatorListView<Carton>(
paginatorListener: boxModel.getBoxes!,
rowBuilder: (p) => CartonListRow(box: p),
color: primaryColor),
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
);
}
}