|
|
|
@ -8,28 +8,30 @@ class PDFScreen extends StatefulWidget {
|
|
|
|
|
final String path; |
|
|
|
|
final int inlet; |
|
|
|
|
|
|
|
|
|
PDFScreen({Key key, this.path,this.inlet}) : super(key: key); |
|
|
|
|
PDFScreen({Key key, this.path, this.inlet}) : super(key: key); |
|
|
|
|
|
|
|
|
|
_PDFScreenState createState() => _PDFScreenState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver { |
|
|
|
|
final Completer<PDFViewController> _controller = Completer<PDFViewController>(); |
|
|
|
|
final Completer<PDFViewController> _controller = |
|
|
|
|
Completer<PDFViewController>(); |
|
|
|
|
int pages = 0; |
|
|
|
|
int currentPage = 0; |
|
|
|
|
int pageTotal =1; |
|
|
|
|
int pageTotal = 0; |
|
|
|
|
bool isReady = false; |
|
|
|
|
String errorMessage = ''; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return widget.inlet == 1 ?Material( |
|
|
|
|
return widget.inlet == 1 |
|
|
|
|
? Material( |
|
|
|
|
type: MaterialType.transparency, |
|
|
|
|
child: Stack( |
|
|
|
|
children: <Widget>[ |
|
|
|
|
Center( |
|
|
|
|
child: Container( |
|
|
|
|
height:250, |
|
|
|
|
height: 250, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
), |
|
|
|
@ -42,8 +44,8 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
pageSnap: true, |
|
|
|
|
defaultPage: currentPage, |
|
|
|
|
fitPolicy: FitPolicy.BOTH, |
|
|
|
|
preventLinkNavigation: |
|
|
|
|
false, // if set to true the link is handled in flutter |
|
|
|
|
preventLinkNavigation: false, |
|
|
|
|
// if set to true the link is handled in flutter |
|
|
|
|
onRender: (_pages) { |
|
|
|
|
setState(() { |
|
|
|
|
pages = _pages; |
|
|
|
@ -69,13 +71,13 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
print('goto uri: $uri'); |
|
|
|
|
}, |
|
|
|
|
onPageChanged: (int page, int total) { |
|
|
|
|
if(total >0){ |
|
|
|
|
if (total > 0) { |
|
|
|
|
print('page change: $page/$total'); |
|
|
|
|
setState(() { |
|
|
|
|
currentPage = page +1; |
|
|
|
|
currentPage = page + 1; |
|
|
|
|
pageTotal = total; |
|
|
|
|
}); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
pageTotal = 1; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -94,14 +96,16 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
//pdfindex显示 |
|
|
|
|
Positioned( |
|
|
|
|
width: MediaQuery.of(context).size.width, |
|
|
|
|
bottom:45, |
|
|
|
|
bottom: 45, |
|
|
|
|
child: Center( |
|
|
|
|
child: Text("${currentPage}/${pageTotal}",style: TextStyle(color: Colors.white,fontSize: 16)), |
|
|
|
|
child: Text("${currentPage}/${pageTotal}", |
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 16)), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
):Scaffold( |
|
|
|
|
) |
|
|
|
|
: Scaffold( |
|
|
|
|
body: Stack( |
|
|
|
|
children: <Widget>[ |
|
|
|
|
PDFView( |
|
|
|
@ -113,8 +117,8 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
pageSnap: true, |
|
|
|
|
defaultPage: currentPage, |
|
|
|
|
fitPolicy: FitPolicy.BOTH, |
|
|
|
|
preventLinkNavigation: |
|
|
|
|
false, // if set to true the link is handled in flutter |
|
|
|
|
preventLinkNavigation: false, |
|
|
|
|
// if set to true the link is handled in flutter |
|
|
|
|
onRender: (_pages) { |
|
|
|
|
setState(() { |
|
|
|
|
pages = _pages; |
|
|
|
@ -139,13 +143,14 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
onLinkHandler: (String uri) { |
|
|
|
|
print('goto uri: $uri'); |
|
|
|
|
}, |
|
|
|
|
onPageChanged: (int page, int total) { if(total >0){ |
|
|
|
|
onPageChanged: (int page, int total) { |
|
|
|
|
if (total > 0) { |
|
|
|
|
print('page change: $page/$total'); |
|
|
|
|
setState(() { |
|
|
|
|
currentPage = page +1; |
|
|
|
|
currentPage = page + 1; |
|
|
|
|
pageTotal = total; |
|
|
|
|
}); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
pageTotal = 1; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -164,23 +169,27 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
|
|
|
|
|
bottom: 45, |
|
|
|
|
width: MediaQuery.of(context).size.width, |
|
|
|
|
child: Center( |
|
|
|
|
child: Text("${currentPage+1}/${pageTotal}",style: TextStyle(color: Colors.black,fontSize: 16)), |
|
|
|
|
child: Text("${currentPage}/${pageTotal}", |
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 16)), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Positioned(//右上角关闭按钮 |
|
|
|
|
Positioned( |
|
|
|
|
//右上角关闭按钮 |
|
|
|
|
right: 10, |
|
|
|
|
top: MediaQuery.of(context).padding.top, |
|
|
|
|
child: IconButton( |
|
|
|
|
icon: Icon(Icons.close,size: 30,color: Colors.black,), |
|
|
|
|
onPressed: (){ |
|
|
|
|
icon: Icon( |
|
|
|
|
Icons.close, |
|
|
|
|
size: 30, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
onPressed: () { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |