wurong
5 months ago
10 changed files with 324 additions and 15 deletions
@ -0,0 +1,125 @@ |
|||||||
|
import 'package:dio/dio.dart'; |
||||||
|
import 'package:flutter/foundation.dart'; |
||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:pdfx/pdfx.dart'; |
||||||
|
|
||||||
|
import '../../retrofit/retrofit_api.dart'; |
||||||
|
|
||||||
|
class PinchPage extends StatefulWidget { |
||||||
|
final String path; |
||||||
|
final int inlet; |
||||||
|
const PinchPage({Key key,this.path,this.inlet}) : super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
State<PinchPage> createState() => _PinchPageState(); |
||||||
|
} |
||||||
|
|
||||||
|
enum DocShown { sample, tutorial, hello, password } |
||||||
|
|
||||||
|
class _PinchPageState extends State<PinchPage> { |
||||||
|
static const int _initialPage = 1; |
||||||
|
PdfControllerPinch _pdfControllerPinch; |
||||||
|
ApiService apiService; |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
apiService = ApiService( |
||||||
|
Dio(), |
||||||
|
context: context, |
||||||
|
); |
||||||
|
_pdfControllerPinch = PdfControllerPinch( |
||||||
|
document: PdfDocument.openData( |
||||||
|
apiService.getUrlFile(widget.path ?? "") |
||||||
|
), |
||||||
|
initialPage: _initialPage, |
||||||
|
); |
||||||
|
super.initState(); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void dispose() { |
||||||
|
_pdfControllerPinch.dispose(); |
||||||
|
super.dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return widget.inlet == 0 ? Scaffold( |
||||||
|
backgroundColor: Colors.white, |
||||||
|
body: Column( |
||||||
|
children: [ |
||||||
|
Container( |
||||||
|
alignment: Alignment.topRight, |
||||||
|
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top,right:10), |
||||||
|
child: IconButton( |
||||||
|
icon: Icon(Icons.close,size: 30,color: Colors.black,), |
||||||
|
onPressed: (){ |
||||||
|
Navigator.of(context).pop(); |
||||||
|
}, |
||||||
|
), |
||||||
|
), |
||||||
|
Expanded(child: PdfViewPinch( |
||||||
|
builders: PdfViewPinchBuilders<DefaultBuilderOptions>( |
||||||
|
options: const DefaultBuilderOptions(), |
||||||
|
documentLoaderBuilder: (_) => |
||||||
|
const Center(child: CircularProgressIndicator()), |
||||||
|
pageLoaderBuilder: (_) => |
||||||
|
const Center(child: CircularProgressIndicator()), |
||||||
|
errorBuilder: (_, error) => Center(child: Text(error.toString())), |
||||||
|
), |
||||||
|
controller: _pdfControllerPinch, |
||||||
|
)), |
||||||
|
Container( |
||||||
|
padding:EdgeInsets.only(bottom:45,top:20), |
||||||
|
width: MediaQuery.of(context).size.width, |
||||||
|
child: Center( |
||||||
|
child: PdfPageNumber( |
||||||
|
controller: _pdfControllerPinch, |
||||||
|
builder: (_, loadingState, page, pagesCount) => Container( |
||||||
|
alignment: Alignment.center, |
||||||
|
child: Text( |
||||||
|
'$page/${pagesCount ?? 0}', |
||||||
|
style: const TextStyle(fontSize:16), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
], |
||||||
|
), |
||||||
|
):Column( |
||||||
|
children: [ |
||||||
|
Expanded(child: Padding( |
||||||
|
padding: EdgeInsets.symmetric(vertical:200), |
||||||
|
child: PdfViewPinch( |
||||||
|
builders: PdfViewPinchBuilders<DefaultBuilderOptions>( |
||||||
|
options: const DefaultBuilderOptions(), |
||||||
|
documentLoaderBuilder: (_) => |
||||||
|
const Center(child: CircularProgressIndicator()), |
||||||
|
pageLoaderBuilder: (_) => |
||||||
|
const Center(child: CircularProgressIndicator()), |
||||||
|
errorBuilder: (_, error) => Center(child: Text(error.toString())), |
||||||
|
), |
||||||
|
controller: _pdfControllerPinch, |
||||||
|
), |
||||||
|
)), |
||||||
|
Container( |
||||||
|
padding:EdgeInsets.only(bottom:45,top:20), |
||||||
|
width: MediaQuery.of(context).size.width, |
||||||
|
child: Center( |
||||||
|
child: PdfPageNumber( |
||||||
|
controller: _pdfControllerPinch, |
||||||
|
builder: (_, loadingState, page, pagesCount) => Container( |
||||||
|
alignment: Alignment.center, |
||||||
|
child: Text( |
||||||
|
'$page/${pagesCount ?? 0}', |
||||||
|
style: const TextStyle(fontSize:16,color: Colors.white), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
], |
||||||
|
); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue