2020-06-24 16:06:15 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:fcs/theme/theme.dart';
|
2020-06-25 09:06:01 +06:30
|
|
|
import 'package:fcs/widget/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';
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
print(' widget.path => ${widget.path}');
|
|
|
|
|
print(' pages => ${pages}');
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: primaryColor,
|
2020-06-25 09:06:01 +06:30
|
|
|
title: LocalText(context, 'pdf_view.title',
|
|
|
|
|
color: Colors.white, fontSize: 20),
|
2020-06-24 16:06:15 +06:30
|
|
|
actions: <Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.share),
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// onError: (error) {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// errorMessage = error.toString();
|
|
|
|
|
// });
|
|
|
|
|
// print(error.toString());
|
|
|
|
|
// },
|
|
|
|
|
// onPageError: (page, error) {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// errorMessage = '$page: ${error.toString()}';
|
|
|
|
|
// });
|
|
|
|
|
// print('$page: ${error.toString()}');
|
|
|
|
|
// },
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
// errorMessage.isEmpty
|
|
|
|
|
// ? !isReady
|
|
|
|
|
// ? Center(
|
|
|
|
|
// child: CircularProgressIndicator(),
|
|
|
|
|
// )
|
|
|
|
|
// : Container()
|
|
|
|
|
// : Center(
|
|
|
|
|
// child: Text(errorMessage),
|
|
|
|
|
// )
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
floatingActionButton: FutureBuilder<PDFViewController>(
|
|
|
|
|
future: _controller.future,
|
|
|
|
|
builder: (context, AsyncSnapshot<PDFViewController> snapshot) {
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
return FloatingActionButton.extended(
|
|
|
|
|
label: Text("Go to ${pages ~/ 2}"),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
await snapshot.data.setPage(pages ~/ 2);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|