import 'dart:async'; import 'dart:io'; import 'package:fcs/model/main_model.dart'; import 'package:fcs/pages/invoice/payment_pdf_screen.dart'; import 'package:fcs/theme/theme.dart'; import 'package:fcs/vo/invoice.dart'; import 'package:fcs/widget/bottom_up_page_route.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; import '../util.dart'; import 'invoice_editor.dart'; import 'payment_page.dart'; class InvoiceListRow extends StatefulWidget { final Invoice invoice; const InvoiceListRow({this.invoice}); @override _InvoiceListRowState createState() => _InvoiceListRowState(); } class _InvoiceListRowState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); final double dotSize = 15.0; Invoice _invoice = new Invoice(); // String pdfPath = 'assets/Invoice-A092(A)-32.pdf'; String pdfPath = ''; @override void initState() { super.initState(); if (widget.invoice != null) { _invoice = widget.invoice; } // fromAsset('assets/demo.pdf', 'demo.pdf').then((f) { // setState(() { // pdfPath = f.path; // }); // }); } Future 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 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; } @override Widget build(BuildContext context) { var owner = Provider.of(context).isOwner(); return Container( padding: EdgeInsets.only(left: 15, right: 15), child: InkWell( onTap: () { owner ? Navigator.of(context) .push(BottomUpPageRoute(InvoiceEditor(invoice: _invoice))) : Navigator.pop(context); // Navigator.of(context).push(BottomUpPageRoute(PaymentPDFScreen( // path: pdfPath, // ))); }, child: Row( children: [ Expanded( child: new Padding( padding: const EdgeInsets.symmetric(vertical: 10.0), child: new Row( children: [ 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: [ 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), ), 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); }, ), ), ], ), ), ); } actionSheet(BuildContext context) { return CupertinoActionSheet( actions: [ CupertinoActionSheetAction( child: Row( children: [ Icon(Icons.file_download), Padding( padding: const EdgeInsets.only(left: 8.0), child: Text( 'Download', style: TextStyle(fontSize: 16, color: Colors.black), ), ), ], ), onPressed: () { Navigator.pop(context); }, ) ], ); } }