update carton and cargo type
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
@@ -16,14 +18,15 @@ import 'package:provider/provider.dart';
|
||||
class PackageList extends StatefulWidget {
|
||||
final bool forCustomer;
|
||||
|
||||
const PackageList({Key? key, this.forCustomer = true}) : super(key: key);
|
||||
const PackageList({super.key, this.forCustomer = true});
|
||||
@override
|
||||
_PackageListState createState() => _PackageListState();
|
||||
}
|
||||
|
||||
class _PackageListState extends State<PackageList> {
|
||||
bool _isLoading = false;
|
||||
int _selectedIndex = 1;
|
||||
bool isLoading = false;
|
||||
int _selectedIndexForCustomer = 1;
|
||||
int _selectedIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -33,8 +36,13 @@ class _PackageListState extends State<PackageList> {
|
||||
|
||||
_init() {
|
||||
var model = context.read<PackageModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.initData(_selectedIndex, widget.forCustomer);
|
||||
if (widget.forCustomer) {
|
||||
_selectedIndexForCustomer = model.selectedIndexForCustomer;
|
||||
model.initDataForCustomer(_selectedIndexForCustomer);
|
||||
} else {
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.initData(_selectedIndex);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
@@ -53,23 +61,23 @@ class _PackageListState extends State<PackageList> {
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "package.popupmenu.active",
|
||||
selected: packageModel.selectedIndex == 1),
|
||||
selected: packageModel.selectedIndexForCustomer == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "package.popupmenu.delivered",
|
||||
selected: packageModel.selectedIndex == 2)
|
||||
selected: packageModel.selectedIndexForCustomer == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
this.setState(() {
|
||||
_selectedIndex = p.id;
|
||||
setState(() {
|
||||
_selectedIndexForCustomer = p.id;
|
||||
});
|
||||
context
|
||||
.read<PackageModel>()
|
||||
.onChanged(_selectedIndex, widget.forCustomer);
|
||||
.onChangedForCustomer(_selectedIndexForCustomer);
|
||||
});
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
inAsyncCall: isLoading,
|
||||
child: Scaffold(
|
||||
appBar: LocalAppBar(
|
||||
labelKey: 'package.title',
|
||||
@@ -84,7 +92,7 @@ class _PackageListState extends State<PackageList> {
|
||||
iconSize: 30,
|
||||
onPressed: () => searchPackage(context,
|
||||
callbackPackageSelect: _searchCallback)),
|
||||
popupMenu
|
||||
widget.forCustomer ? popupMenu : _menuFilteringWidget(context)
|
||||
],
|
||||
),
|
||||
body: PaginatorListView<Package>(
|
||||
@@ -98,11 +106,77 @@ class _PackageListState extends State<PackageList> {
|
||||
|
||||
_searchCallback(Package package) async {
|
||||
var packageModel = Provider.of<PackageModel>(context, listen: false);
|
||||
Package? _package = await packageModel.getPackage(package.id!);
|
||||
if (_package == null) return;
|
||||
Package? package0 = await packageModel.getPackage(package.id!);
|
||||
if (package0 == null) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => PackageInfo(package: _package)),
|
||||
CupertinoPageRoute(builder: (context) => PackageInfo(package: package0)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _menuFilteringWidget(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: PopupMenuButton<LocalPopupMenu>(
|
||||
elevation: 3.2,
|
||||
tooltip: '',
|
||||
onSelected: (choice) async {
|
||||
setState(() {
|
||||
_selectedIndex = choice.id;
|
||||
});
|
||||
|
||||
await context.read<PackageModel>().onChanged(choice.id);
|
||||
},
|
||||
icon: SizedBox(
|
||||
width: 30,
|
||||
height: 30,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
const Icon(
|
||||
Icons.filter_list,
|
||||
color: Colors.white,
|
||||
),
|
||||
_selectedIndex != 0
|
||||
? Positioned(
|
||||
bottom: 15,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return packageFiteringMenu.map((LocalPopupMenu choice) {
|
||||
return PopupMenuItem<LocalPopupMenu>(
|
||||
value: choice,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: Text("${choice.text}",
|
||||
style: TextStyle(color: Colors.black))),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
_selectedIndex == choice.id
|
||||
? const Icon(
|
||||
Icons.check,
|
||||
color: Colors.grey,
|
||||
)
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user