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-26 04:41:24 +06:30
|
|
|
import 'package:fcs/helpers/cache_mgr.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-10-26 04:41:24 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-14 20:56:46 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
2020-10-26 04:41:24 +06:30
|
|
|
import 'package:fcs/pages/widgets/progress.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-16 21:38:39 +06:30
|
|
|
import 'package:share/share.dart';
|
2020-06-24 16:06:15 +06:30
|
|
|
|
|
|
|
|
class PaymentPDFScreen extends StatefulWidget {
|
2020-10-26 04:41:24 +06:30
|
|
|
final String url;
|
2020-06-24 16:06:15 +06:30
|
|
|
|
2020-10-26 04:41:24 +06:30
|
|
|
PaymentPDFScreen({Key key, this.url}) : super(key: key);
|
2020-06-24 16:06:15 +06:30
|
|
|
|
|
|
|
|
_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 = '';
|
2020-10-26 04:41:24 +06:30
|
|
|
bool _isLoading = true;
|
|
|
|
|
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
download();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File file;
|
|
|
|
|
Future<void> download() async {
|
|
|
|
|
try {
|
|
|
|
|
File f = await PdfCacheMgr.pdfs.getSingleFile(widget.url);
|
|
|
|
|
setState(() {
|
|
|
|
|
file = f;
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-24 16:06:15 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-26 04:41:24 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
title: LocalText(context, 'invoice.pdf',
|
|
|
|
|
color: Colors.white, fontSize: 20),
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2020-06-24 16:06:15 +06:30
|
|
|
),
|
2020-10-26 04:41:24 +06:30
|
|
|
actions: <Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.share,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: _share,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Stack(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
_isLoading
|
|
|
|
|
? Container()
|
|
|
|
|
: PDFView(
|
|
|
|
|
filePath: file?.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-06-24 16:06:15 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-10-16 21:38:39 +06:30
|
|
|
|
2020-10-26 04:41:24 +06:30
|
|
|
_share() async {
|
2020-10-16 21:38:39 +06:30
|
|
|
final RenderBox box = context.findRenderObject();
|
2020-10-26 04:41:24 +06:30
|
|
|
await Share.shareFiles([file.path],
|
|
|
|
|
mimeTypes: ["application/pdf"],
|
|
|
|
|
subject: "Invoice",
|
2020-10-16 21:38:39 +06:30
|
|
|
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
|
|
|
|
|
}
|
2020-06-24 16:06:15 +06:30
|
|
|
}
|