import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/invoice/invoice_shipment_list.dart'; import 'package:fcs/pages/invoice/model/invoice_model.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_popup_menu_button.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:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../domain/entities/invoice.dart'; import '../../pagination/paginator_listview.dart'; import 'invoice_list_row.dart'; class InvoiceList extends StatefulWidget { final bool forCustomer; const InvoiceList({Key? key, required this.forCustomer}) : super(key: key); @override _InvoiceListState createState() => _InvoiceListState(); } class _InvoiceListState extends State { bool _isLoading = false; int _selectedIndex = 1; @override void initState() { super.initState(); _init(); } _init() { var model = context.read(); _selectedIndex = model.selectedIndex; model.loadPaginationInvoices(_selectedIndex, widget.forCustomer); if (mounted) { setState(() {}); } } @override Widget build(BuildContext context) { var invoiceModel = Provider.of(context); final popupMenu = LocalPopupMenuButton( popmenus: [ LocalPopupMenu( id: 1, textKey: "invoice.popupmenu.issused", selected: invoiceModel.selectedIndex == 1), LocalPopupMenu( id: 2, textKey: "invoice.popupmenu.paid", selected: invoiceModel.selectedIndex == 2), LocalPopupMenu( id: 3, textKey: "invoice.popupmenu.cancel", selected: invoiceModel.selectedIndex == 3) ], popupMenuCallback: (p) { this.setState(() { _selectedIndex = p.id; }); context .read() .onChanged(_selectedIndex, widget.forCustomer); }); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: LocalAppBar( labelKey: 'invoices.title', actions: [popupMenu]), floatingActionButton: (widget.forCustomer) ? null : FloatingActionButton.extended( onPressed: () { _newInvoice(); }, icon: Icon(Icons.add), label: LocalText(context, 'invoices.add', color: Colors.white), backgroundColor: primaryColor, ), body: PaginatorListView( paginatorListener: invoiceModel.getInvoices!, rowBuilder: (p) => InvoiceListRow(invoice: p, isCustomer: widget.forCustomer), color: primaryColor)), ); } _newInvoice() async { Navigator.of(context) .push(CupertinoPageRoute(builder: (context) => InvoiceShipmentList())); } }