2020-10-26 04:41:24 +06:30
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:fcs/helpers/api_helper.dart';
|
|
|
|
|
import 'package:fcs/helpers/firebase_helper.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-10-14 20:56:46 +06:30
|
|
|
import 'package:fcs/pages/invoice/invoice_shipment_list.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/invoice/model/invoice_model.dart';
|
2020-10-26 04:41:24 +06:30
|
|
|
import 'package:fcs/pages/invoice/payment_pdf_screen.dart';
|
2020-10-15 15:49:02 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-12 03:34:05 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-10-19 05:13:49 +06:30
|
|
|
import 'package:flutter/material.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'invoice_list_row.dart';
|
|
|
|
|
|
|
|
|
|
class InvoiceList extends StatefulWidget {
|
2020-10-16 21:38:39 +06:30
|
|
|
final bool forCustomer;
|
2020-10-16 13:46:02 +06:30
|
|
|
|
2020-10-16 21:38:39 +06:30
|
|
|
const InvoiceList({Key key, this.forCustomer}) : super(key: key);
|
2020-06-02 14:56:51 +06:30
|
|
|
@override
|
|
|
|
|
_InvoiceListState createState() => _InvoiceListState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _InvoiceListState extends State<InvoiceList> {
|
|
|
|
|
bool _isLoading = false;
|
2020-10-16 13:46:02 +06:30
|
|
|
var _controller = ScrollController();
|
2020-06-02 14:56:51 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2020-10-16 21:38:39 +06:30
|
|
|
_controller.addListener(() async {
|
|
|
|
|
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
|
2020-10-19 05:13:49 +06:30
|
|
|
Provider.of<InvoiceModel>(context, listen: false)
|
|
|
|
|
.loadMore(isCustomer: widget.forCustomer);
|
2020-10-16 21:38:39 +06:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-26 04:41:24 +06:30
|
|
|
Provider.of<InvoiceModel>(context, listen: false)
|
|
|
|
|
.initData(widget.forCustomer, true, false);
|
2020-06-02 14:56:51 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-07 02:33:06 +06:30
|
|
|
var owner = true;
|
2020-10-09 19:00:39 +06:30
|
|
|
var invoiceModel = Provider.of<InvoiceModel>(context);
|
2020-07-02 16:16:21 +06:30
|
|
|
|
2020-10-15 15:49:02 +06:30
|
|
|
final popupMenu = LocalPopupMenuButton(
|
|
|
|
|
popmenus: [
|
|
|
|
|
LocalPopupMenu(
|
2020-10-16 21:38:39 +06:30
|
|
|
id: 1,
|
2020-10-26 04:41:24 +06:30
|
|
|
textKey: "invoice.popupmenu.issused",
|
2020-10-16 21:38:39 +06:30
|
|
|
selected: invoiceModel.selectedIndex == 1),
|
|
|
|
|
LocalPopupMenu(
|
|
|
|
|
id: 2,
|
|
|
|
|
textKey: "invoice.popupmenu.paid",
|
2020-10-26 04:41:24 +06:30
|
|
|
selected: invoiceModel.selectedIndex == 2),
|
|
|
|
|
LocalPopupMenu(
|
|
|
|
|
id: 3,
|
|
|
|
|
textKey: "invoice.popupmenu.cancel",
|
|
|
|
|
selected: invoiceModel.selectedIndex == 3)
|
2020-10-15 15:49:02 +06:30
|
|
|
],
|
|
|
|
|
popupMenuCallback: (p) => this.setState(() {
|
2020-10-26 04:41:24 +06:30
|
|
|
invoiceModel.selectedIndex = p.id;
|
|
|
|
|
if (p.id == 2) {
|
|
|
|
|
Provider.of<InvoiceModel>(context, listen: false)
|
|
|
|
|
.initData(widget.forCustomer, false, true);
|
|
|
|
|
} else if (p.id == 3) {
|
|
|
|
|
Provider.of<InvoiceModel>(context, listen: false)
|
|
|
|
|
.initData(widget.forCustomer, true, false);
|
|
|
|
|
} else {
|
|
|
|
|
Provider.of<InvoiceModel>(context, listen: false)
|
|
|
|
|
.initData(widget.forCustomer, true, false);
|
|
|
|
|
}
|
2020-10-15 15:49:02 +06:30
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2020-06-02 14:56:51 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: DefaultTabController(
|
2020-07-02 16:16:21 +06:30
|
|
|
length: 2,
|
2020-06-02 14:56:51 +06:30
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
2020-10-12 03:34:05 +06:30
|
|
|
icon: new Icon(CupertinoIcons.back),
|
2020-06-02 14:56:51 +06:30
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
title: LocalText(context, 'invoices.title',
|
|
|
|
|
color: Colors.white, fontSize: 20),
|
2020-10-22 04:14:53 +06:30
|
|
|
actions: <Widget>[popupMenu],
|
2020-06-02 14:56:51 +06:30
|
|
|
),
|
2020-08-30 21:26:37 +06:30
|
|
|
floatingActionButton: owner
|
|
|
|
|
? FloatingActionButton.extended(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_newInvoice();
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.add),
|
|
|
|
|
label:
|
2020-10-09 19:00:39 +06:30
|
|
|
LocalText(context, 'invoices.add', color: Colors.white),
|
2020-08-30 21:26:37 +06:30
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
)
|
|
|
|
|
: null,
|
2020-10-09 19:00:39 +06:30
|
|
|
body: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
2020-10-16 21:38:39 +06:30
|
|
|
child: RefreshIndicator(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
physics: AlwaysScrollableScrollPhysics(),
|
|
|
|
|
controller: _controller,
|
|
|
|
|
separatorBuilder: (context, index) => Divider(
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
padding: EdgeInsets.only(top: 15),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: invoiceModel.invoices.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
return InvoiceListRow(
|
|
|
|
|
key: ValueKey(invoiceModel.invoices[index].id),
|
|
|
|
|
invoice: invoiceModel.invoices[index]);
|
|
|
|
|
}),
|
|
|
|
|
onRefresh: () => invoiceModel.refresh(),
|
|
|
|
|
),
|
2020-10-09 19:00:39 +06:30
|
|
|
),
|
2020-10-16 21:38:39 +06:30
|
|
|
invoiceModel.isLoading
|
|
|
|
|
? Container(
|
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text("Loading...",
|
|
|
|
|
style: TextStyle(color: Colors.white)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
2020-10-09 19:00:39 +06:30
|
|
|
],
|
2020-06-02 14:56:51 +06:30
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 04:41:24 +06:30
|
|
|
_newInvoice() async {
|
2020-10-14 13:54:42 +06:30
|
|
|
Navigator.of(context)
|
2020-10-14 20:56:46 +06:30
|
|
|
.push(CupertinoPageRoute(builder: (context) => InvoiceShipmentList()));
|
2020-06-02 14:56:51 +06:30
|
|
|
}
|
|
|
|
|
}
|