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

112 lines
3.5 KiB
Dart
Raw Normal View History

2020-06-24 16:06:15 +06:30
import 'dart:async';
2020-10-16 21:38:39 +06:30
import 'dart:io';
2020-06-24 16:06:15 +06:30
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-10-16 21:38:39 +06:30
import 'package:fcs/pages/main/model/main_model.dart';
2020-10-14 20:56:46 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-06-24 16:06:15 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
2020-10-17 01:40:24 +06:30
import 'package:http/http.dart' as http;
2020-10-16 21:38:39 +06:30
import 'package:provider/provider.dart';
import 'package:share/share.dart';
2020-06-24 16:06:15 +06:30
class PaymentPDFScreen extends StatefulWidget {
final String path;
PaymentPDFScreen({Key key, this.path}) : super(key: key);
_PaymentPDFScreenState createState() => _PaymentPDFScreenState();
}
class _PaymentPDFScreenState extends State<PaymentPDFScreen>
with WidgetsBindingObserver {
final Completer<PDFViewController> _controller =
Completer<PDFViewController>();
int pages = 0;
int currentPage = 0;
bool isReady = false;
String errorMessage = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2020-10-15 18:48:32 +06:30
centerTitle: true,
2020-06-24 16:06:15 +06:30
backgroundColor: primaryColor,
2020-10-14 20:56:46 +06:30
title: LocalText(context, 'invoice.pdf',
color: Colors.white, fontSize: 20),
2020-10-14 13:54:42 +06:30
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () {
Navigator.of(context).pop();
}),
2020-06-24 16:06:15 +06:30
actions: <Widget>[
2020-10-14 20:56:46 +06:30
IconButton(
icon: Icon(Icons.file_download),
2020-10-16 13:46:02 +06:30
onPressed: () async {
2020-10-16 21:38:39 +06:30
// var _dir = (await getApplicationDocumentsDirectory()).path;
// _downloadFile(widget.path, 'invoice.pdf', _dir);
2020-10-16 13:46:02 +06:30
},
2020-10-14 20:56:46 +06:30
),
2020-06-24 16:06:15 +06:30
IconButton(
icon: Icon(Icons.share),
2020-10-16 21:38:39 +06:30
onPressed: () => _share(widget.path),
2020-06-24 16:06:15 +06:30
),
],
),
body: Stack(
children: <Widget>[
PDFView(
filePath: widget.path,
enableSwipe: true,
swipeHorizontal: true,
autoSpacing: false,
pageFling: true,
pageSnap: true,
defaultPage: currentPage,
fitPolicy: FitPolicy.BOTH,
preventLinkNavigation:
false, // if set to true the link is handled in flutter
onRender: (_pages) {
print(('pages => $pages'));
setState(() {
pages = _pages;
isReady = true;
});
},
onViewCreated: (PDFViewController pdfViewController) {
_controller.complete(pdfViewController);
},
onLinkHandler: (String uri) {
print('goto uri: $uri');
},
onPageChanged: (int page, int total) {
print('page change: $page/$total');
setState(() {
currentPage = page;
});
},
),
],
),
);
}
2020-10-16 21:38:39 +06:30
Future<File> _downloadFile(String url, String filename, String dir) async {
var req = await http.Client().get(Uri.parse(url));
var file = File('$dir/$filename');
return file.writeAsBytes(req.bodyBytes);
}
_share(String url) async {
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
String appUrl = mainModel.setting.appUrl;
final RenderBox box = context.findRenderObject();
await Share.share(
"Join us on FCS Logistics App. Here is the link:\n $appUrl\n" + url,
subject: "Invitation to FCS Logistics App",
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
}
2020-06-24 16:06:15 +06:30
}