2020-06-24 16:06:15 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:fcs/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/pages/invoice/payment_pdf_screen.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
import 'package:fcs/theme/theme.dart';
|
|
|
|
|
import 'package:fcs/vo/invoice.dart';
|
|
|
|
|
import 'package:fcs/widget/bottom_up_page_route.dart';
|
2020-06-24 16:06:15 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
import 'package:flutter/material.dart';
|
2020-06-24 16:06:15 +06:30
|
|
|
import 'package:flutter/services.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
2020-06-24 16:06:15 +06:30
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
|
|
|
|
|
import '../util.dart';
|
|
|
|
|
import 'invoice_editor.dart';
|
2020-06-24 16:06:15 +06:30
|
|
|
import 'payment_page.dart';
|
2020-06-02 14:56:51 +06:30
|
|
|
|
|
|
|
|
class InvoiceListRow extends StatefulWidget {
|
|
|
|
|
final Invoice invoice;
|
|
|
|
|
const InvoiceListRow({this.invoice});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_InvoiceListRowState createState() => _InvoiceListRowState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _InvoiceListRowState extends State<InvoiceListRow> {
|
|
|
|
|
var dateFormatter = new DateFormat('dd MMM yyyy');
|
|
|
|
|
final double dotSize = 15.0;
|
|
|
|
|
Invoice _invoice = new Invoice();
|
2020-06-24 16:06:15 +06:30
|
|
|
String pdfPath = '';
|
2020-06-02 14:56:51 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
if (widget.invoice != null) {
|
|
|
|
|
_invoice = widget.invoice;
|
|
|
|
|
}
|
2020-06-24 16:06:15 +06:30
|
|
|
|
2020-06-29 16:03:41 +06:30
|
|
|
fromAsset('assets/Invoice-A092(A)-32.pdf', 'Invoice-A092(A)-32.pdf')
|
|
|
|
|
.then((f) {
|
|
|
|
|
setState(() {
|
|
|
|
|
pdfPath = f.path;
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-06-24 16:06:15 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<File> fromAsset(String asset, String filename) async {
|
|
|
|
|
// To open from assets, you can copy them to the app storage folder, and the access them "locally"
|
|
|
|
|
Completer<File> completer = Completer();
|
|
|
|
|
print('asset => $asset');
|
|
|
|
|
print('assest => ${await rootBundle.load(asset)}');
|
|
|
|
|
try {
|
|
|
|
|
var dir = await getApplicationDocumentsDirectory();
|
|
|
|
|
File file = File("${dir.path}/$filename");
|
|
|
|
|
var data = await rootBundle.load(asset);
|
|
|
|
|
print('data => $data');
|
|
|
|
|
var bytes = data.buffer.asUint8List();
|
|
|
|
|
await file.writeAsBytes(bytes, flush: true);
|
|
|
|
|
completer.complete(file);
|
|
|
|
|
} catch (e) {
|
2020-06-25 09:06:01 +06:30
|
|
|
throw Exception('Error parsing asset file! ===> ' + e.toString());
|
2020-06-24 16:06:15 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return completer.future;
|
2020-06-02 14:56:51 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-06-24 16:06:15 +06:30
|
|
|
var owner = Provider.of<MainModel>(context).isOwner();
|
2020-06-02 14:56:51 +06:30
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 15, right: 15),
|
2020-06-29 16:03:41 +06:30
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: new Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
owner
|
|
|
|
|
? Navigator.of(context).push(
|
|
|
|
|
BottomUpPageRoute(InvoiceEditor(invoice: _invoice)))
|
|
|
|
|
: Navigator.of(context)
|
|
|
|
|
.push(BottomUpPageRoute(PaymentPDFScreen(
|
|
|
|
|
path: pdfPath,
|
|
|
|
|
)));
|
|
|
|
|
},
|
2020-06-02 14:56:51 +06:30
|
|
|
child: new Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 5, right: 10),
|
|
|
|
|
child: Icon(
|
|
|
|
|
FontAwesomeIcons.fileInvoice,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
size: 30,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
new Expanded(
|
|
|
|
|
child: new Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
|
child: new Text(
|
|
|
|
|
_invoice.invoiceNumber == null
|
|
|
|
|
? ''
|
|
|
|
|
: _invoice.invoiceNumber,
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
fontSize: 15.0, color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
|
|
|
|
child: new Text(
|
|
|
|
|
dateFormatter.format(_invoice.invoiceDate),
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
fontSize: 15.0, color: Colors.grey),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-06-29 16:03:41 +06:30
|
|
|
),
|
2020-07-02 16:16:21 +06:30
|
|
|
// Padding(
|
|
|
|
|
// padding: const EdgeInsets.all(0),
|
|
|
|
|
// child: getStatus(_invoice.status),
|
|
|
|
|
// ),
|
|
|
|
|
_invoice.status=="Pending"?
|
2020-06-29 16:03:41 +06:30
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 10.0),
|
|
|
|
|
child: InkWell(
|
2020-07-02 16:16:21 +06:30
|
|
|
child: RaisedButton(
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.payment,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left:8.0),
|
|
|
|
|
child: Text("Payment"),
|
|
|
|
|
)
|
|
|
|
|
],
|
2020-06-24 16:06:15 +06:30
|
|
|
),
|
2020-07-02 16:16:21 +06:30
|
|
|
onPressed: () {
|
2020-06-29 16:03:41 +06:30
|
|
|
Navigator.of(context)
|
|
|
|
|
.push(BottomUpPageRoute(PaymentPage(invoice: _invoice)));
|
|
|
|
|
},
|
2020-07-02 16:16:21 +06:30
|
|
|
)),
|
|
|
|
|
):Container(),
|
2020-06-29 16:03:41 +06:30
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
|
child: InkWell(
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.more_vert,
|
|
|
|
|
color: primaryColor,
|
2020-06-24 16:06:15 +06:30
|
|
|
),
|
2020-06-29 16:03:41 +06:30
|
|
|
onTap: () {
|
|
|
|
|
var act = actionSheet(context);
|
|
|
|
|
showCupertinoModalPopup(
|
|
|
|
|
context: context, builder: (BuildContext context) => act);
|
|
|
|
|
},
|
2020-06-24 16:06:15 +06:30
|
|
|
),
|
2020-06-29 16:03:41 +06:30
|
|
|
),
|
|
|
|
|
],
|
2020-06-02 14:56:51 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-24 16:06:15 +06:30
|
|
|
|
|
|
|
|
actionSheet(BuildContext context) {
|
|
|
|
|
return CupertinoActionSheet(
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
CupertinoActionSheetAction(
|
2020-06-25 09:06:01 +06:30
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Icon(Icons.file_download),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
'Download',
|
|
|
|
|
style: TextStyle(fontSize: 16, color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2020-06-24 16:06:15 +06:30
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-02 14:56:51 +06:30
|
|
|
}
|