Skip to content

Instantly share code, notes, and snippets.

@Classy-Bear
Created January 10, 2020 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Classy-Bear/51ce6687929ef5b274b48e1c91707aa9 to your computer and use it in GitHub Desktop.
Save Classy-Bear/51ce6687929ef5b274b48e1c91707aa9 to your computer and use it in GitHub Desktop.
class PdfViewPage extends StatefulWidget {
final String path;
const PdfViewPage({Key key, this.path}) : super(key: key);
@override
_PdfViewPageState createState() => _PdfViewPageState();
}
class _PdfViewPageState extends State<PdfViewPage> {
int _total_de_paginas = 0;
int _pagina_actual = 0;
bool _estaListoPDF = false;
PDFViewController _pdfViewController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("My Document"),
),
body: Stack(
children: <Widget>[
PDFView(
filePath: widget.path,
swipeHorizontal: true,
onError: (e) {
print(e);
},
onRender: (_pages) {
setState(() {
_total_de_paginas = _pages;
_estaListoPDF = true;
});
},
onViewCreated: (PDFViewController vc) {
_pdfViewController = vc;
},
onPageChanged: (int page, int total) {
setState(() {});
},
onPageError: (page, e) {},
),
!_estaListoPDF
? Center(
child: CircularProgressIndicator(),
)
: Offstage()
],
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
_pagina_actual > 0
? FloatingActionButton.extended(
backgroundColor: Colors.red,
label: Text("Go to ${_pagina_actual - 1}"),
onPressed: () {
_pagina_actual -= 1;
_pdfViewController.setPage(_pagina_actual);
},
)
: Offstage(),
_pagina_actual+1 < _total_de_paginas
? FloatingActionButton.extended(
backgroundColor: Colors.green,
label: Text("Go to ${_pagina_actual + 1}"),
onPressed: () {
_currentPage += 1;
_pdfViewController.setPage(_pagina_actual);
},
)
: Offstage(),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment