Add optional two page mode
This commit is contained in:
@@ -26,6 +26,7 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
bool isFullscreen = false;
|
||||
late Future<bool> documentLoaded;
|
||||
PdfDocument? document;
|
||||
bool twoPageMode = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -79,58 +80,77 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
if (snapshot.hasData && document != null) {
|
||||
numPages = document!.pages.length;
|
||||
|
||||
return GestureDetector(
|
||||
onTapUp: (TapUpDetails details) {
|
||||
// Get the size of the screen
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.bottomLeft,
|
||||
margin: EdgeInsets.all(10),
|
||||
child: FloatingActionButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
twoPageMode = !twoPageMode;
|
||||
});
|
||||
},
|
||||
child: Icon(twoPageMode ? Icons.filter_1 : Icons.filter_2),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTapUp: (TapUpDetails details) {
|
||||
// Get the size of the screen
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
// print("Touch at y = ${details.localPosition.dy}");
|
||||
// print("Touch at x = ${details.localPosition.dx}");
|
||||
// print("Screenwidth = ${screenWidth}");
|
||||
// Check where the user tapped
|
||||
// if (details.localPosition.dy < 100) {
|
||||
// TODO
|
||||
// setState(() {
|
||||
// toggleFullscreen();
|
||||
// });
|
||||
if (details.localPosition.dx < screenWidth / 2) {
|
||||
// Left half of the screen
|
||||
setState(() {
|
||||
page = page > 1 ? page - 1 : 1;
|
||||
});
|
||||
} else {
|
||||
// Right half of the screen
|
||||
setState(() {
|
||||
page = page < numPages ? page + 1 : numPages;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Stack(
|
||||
// print("Touch at y = ${details.localPosition.dy}");
|
||||
// print("Touch at x = ${details.localPosition.dx}");
|
||||
// print("Screenwidth = ${screenWidth}");
|
||||
// Check where the user tapped
|
||||
// if (details.localPosition.dy < 100) {
|
||||
// TODO
|
||||
// setState(() {
|
||||
// toggleFullscreen();
|
||||
// });
|
||||
if (details.localPosition.dx < screenWidth / 2) {
|
||||
// Left half of the screen
|
||||
setState(() {
|
||||
page = page > 1 ? page - 1 : 1;
|
||||
});
|
||||
} else {
|
||||
// Right half of the screen
|
||||
setState(() {
|
||||
page = page < numPages ? page + 1 : numPages;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
PdfPageView(
|
||||
key: ValueKey(page),
|
||||
document: document,
|
||||
pageNumber: page,
|
||||
alignment: Alignment.center,
|
||||
Stack(
|
||||
children: [
|
||||
PdfPageView(
|
||||
key: ValueKey(page),
|
||||
document: document,
|
||||
pageNumber: page,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
Container(
|
||||
alignment: Alignment.bottomCenter,
|
||||
padding: EdgeInsets.only(bottom: 5),
|
||||
child: Text('$page / $numPages'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
alignment: Alignment.bottomCenter,
|
||||
padding: EdgeInsets.only(bottom: 5),
|
||||
child: Text('$page / $numPages'),
|
||||
Visibility(
|
||||
visible: twoPageMode == true,
|
||||
child: PdfPageView(
|
||||
key: ValueKey(page),
|
||||
document: document,
|
||||
pageNumber: page + 1,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// PdfPageView(
|
||||
// key: ValueKey(page),
|
||||
// document: document,
|
||||
// pageNumber: page + 1,
|
||||
// alignment: Alignment.center,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Center(
|
||||
|
||||
Reference in New Issue
Block a user