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