-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[native_pdf_view] Provide a onPageChanged callback #19
Labels
enhancement
New feature or request
Comments
Show code exampleimport 'package:flutter/material.dart';
import 'package:native_pdf_view/native_pdf_view.dart';
import 'package:native_pdf_view_example/has_support.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// Create page controller
final _pageController = PageController();
int _actualPageNumber = 1;
@override
void initState() {
// listen page number change
_pageController.addListener(() {
final pageIndex = _pageController.page.round();
final pageNumber = pageIndex + 1;
// Set actual page
if (pageNumber != _actualPageNumber) {
setState(() {
_actualPageNumber = pageNumber;
});
}
});
super.initState();
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => MaterialApp(
theme: ThemeData(primaryColor: Colors.white),
home: Scaffold(
appBar: AppBar(title: Text('PDFView example')),
body: FutureBuilder<PDFDocument>(
future: _getDocument(),
builder: (_, snapshot) {
if (snapshot.hasData) {
return Stack(
children: <Widget>[
PDFView(
controller: _pageController, // set page controller
document: snapshot.data,
),
Align(
alignment: Alignment.center,
child: Text(
'$_actualPageNumber/${snapshot.data.pagesCount}',
style: TextStyle(fontSize: 34),
),
)
],
);
}
if (snapshot.hasError) {
return Center(
child: Text(
'PDF Rendering does not '
'support on the system of this version',
),
);
}
return Center(child: CircularProgressIndicator());
},
),
),
);
Future<PDFDocument> _getDocument() async {
if (await hasSupport()) {
return PDFDocument.openAsset('assets/sample.pdf');
} else {
throw Exception(
'PDF Rendering does not '
'support on the system of this version',
);
}
}
} @IchordeDionysos will this solve your problem? |
Got your idea, I agree |
Yes, the example you provided worked, but is so think far less beautiful and less intuitive/obvious to us :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
We would like to show the user that he is on page 1/n,
Describe the solution you'd like
To achieve that I believe that a simple
onPageChanged
callback could be easily implemented and would give us a lot of flexibility.Describe alternatives you've considered
A built-in page indicator would also work, but might not fit into the UI of every app.
Additional context
The text was updated successfully, but these errors were encountered: