Files
fcs/lib/pages/invoice/invoice_list_row.dart

179 lines
5.7 KiB
Dart
Raw Normal View History

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 = 'assets/Invoice-A092(A)-32.pdf';
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
fromAsset('assets/demo.pdf', 'demo.pdf').then((f) {
setState(() {
pdfPath = f.path;
});
});
}
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) {
throw Exception('Error parsing asset file!'+ e.toString());
}
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),
child: InkWell(
onTap: () {
2020-06-24 16:06:15 +06:30
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: Row(
children: <Widget>[
Expanded(
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
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),
),
)
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(0),
child: getStatus(_invoice.status),
),
2020-06-24 16:06:15 +06:30
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: InkWell(
child: Icon(
Icons.payment,
color: primaryColor,
),
onTap: () {
Navigator.of(context)
.push(BottomUpPageRoute(PaymentPage(invoice: _invoice)));
},
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: InkWell(
child: Icon(
Icons.more_vert,
color: primaryColor,
),
onTap: () {
var act = actionSheet(context);
showCupertinoModalPopup(
context: context, builder: (BuildContext context) => act);
},
),
),
2020-06-02 14:56:51 +06:30
],
),
),
);
}
2020-06-24 16:06:15 +06:30
actionSheet(BuildContext context) {
return CupertinoActionSheet(
actions: <Widget>[
CupertinoActionSheetAction(
child: Text("Download"),
onPressed: () {
Navigator.pop(context);
},
)
],
);
}
2020-06-02 14:56:51 +06:30
}