import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/domain/vo/local_popupmenu.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:fcs/pagination/paginator_listview.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../domain/entities/fcs_shipment.dart'; import 'fcs_shipment_editor.dart'; import 'fcs_shipment_list_row.dart'; class FcsShipmentList extends StatefulWidget { @override _FcsShipmentListState createState() => _FcsShipmentListState(); } class _FcsShipmentListState extends State { bool _isLoading = false; int _selectedIndex = 0; @override void initState() { super.initState(); _init(); } _init() { var model = context.read(); _selectedIndex = model.selectedIndex; model.loadFcsShipments(_selectedIndex); if (mounted) { setState(() {}); } } @override Widget build(BuildContext context) { var shipmentModel = Provider.of(context); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: LocalAppBar(labelKey: "FCSshipment.list.title", actions: [ _menuFilteringWidget(context), ]), floatingActionButton: FloatingActionButton.extended( onPressed: () { _newShipment(); }, icon: Icon(Icons.add), label: LocalText(context, "FCSshipment.add", color: Colors.white), backgroundColor: primaryColor), body: PaginatorListView( paginatorListener: shipmentModel.fcsShipments!, rowBuilder: (p) => FcsShipmentListRow(shipment: p), color: primaryColor))); } _newShipment() { Navigator.of(context) .push(CupertinoPageRoute(builder: (context) => FcsShipmentEditor())); } Widget _menuFilteringWidget(BuildContext context) { return PopupMenuButton( splashRadius: 25, padding: const EdgeInsets.only(right: 15), elevation: 3.2, tooltip: 'This is tooltip', onSelected: (choice) async { setState(() { _selectedIndex = choice.id; }); await context.read().onChanged(choice.id); }, icon: Stack( alignment: Alignment.center, children: [ 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 shipFiteringMenu.map((LocalPopupMenu choice) { return PopupMenuItem( value: choice, child: Row( children: [ Flexible(child: Text("${choice.text}")), const SizedBox( width: 10, ), _selectedIndex == choice.id ? const Icon( Icons.check, color: Colors.grey, ) : const SizedBox(), ], ), ); }).toList(); }); } }