From 363f3641fbe5700deee5e86af143a85f48dd6ae9 Mon Sep 17 00:00:00 2001 From: nyne Date: Wed, 30 Oct 2024 10:13:30 +0800 Subject: [PATCH] improve reader --- lib/pages/reader/images.dart | 7 ++++-- lib/pages/reader/scaffold.dart | 41 +++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/pages/reader/images.dart b/lib/pages/reader/images.dart index 6e7c91c..f1c427f 100644 --- a/lib/pages/reader/images.dart +++ b/lib/pages/reader/images.dart @@ -116,6 +116,9 @@ class _GalleryModeState extends State<_GalleryMode> controller = PageController(initialPage: reader.page); reader._imageViewController = this; cached = List.filled(reader.maxPage + 2, false); + Future.microtask(() { + context.readerScaffold.setFloatingButton(0); + }); super.initState(); } @@ -180,11 +183,11 @@ class _GalleryModeState extends State<_GalleryMode> ), onPageChanged: (i) { if (i == 0) { - if (!reader.toNextChapter()) { + if (!reader.toPrevChapter()) { reader.toPage(1); } } else if (i == reader.maxPage + 1) { - if (!reader.toPrevChapter()) { + if (!reader.toNextChapter()) { reader.toPage(reader.maxPage); } } else { diff --git a/lib/pages/reader/scaffold.dart b/lib/pages/reader/scaffold.dart index bb327d8..96d1de8 100644 --- a/lib/pages/reader/scaffold.dart +++ b/lib/pages/reader/scaffold.dart @@ -20,9 +20,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { int showFloatingButtonValue = 0; + var lastValue = 0; + double fABValue = 0; void setFloatingButton(int value) { + lastValue = showFloatingButtonValue; if (value == 0) { if (showFloatingButtonValue != 0) { showFloatingButtonValue = 0; @@ -79,6 +82,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { child: widget.child, ), buildPageInfoText(), + AnimatedPositioned( + duration: const Duration(milliseconds: 180), + right: 16, + bottom: showFloatingButtonValue == 0 ? -58 : 16, + child: buildEpChangeButton(), + ), AnimatedPositioned( duration: const Duration(milliseconds: 180), top: _isOpen ? 0 : -(kTopBarHeight + context.padding.top), @@ -95,12 +104,6 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { height: kBottomBarHeight + context.padding.bottom, child: buildBottom(), ), - AnimatedPositioned( - duration: const Duration(milliseconds: 180), - right: 16, - bottom: showFloatingButtonValue == 0 ? -58 : 16, - child: buildEpChangeButton(), - ), ], ); } @@ -163,14 +166,22 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { children: [ const SizedBox(width: 8), IconButton.filledTonal( - onPressed: context.reader.toPrevChapter, + onPressed: () { + if(!context.reader.toPrevChapter()) { + context.reader.toPage(1); + } + }, icon: const Icon(Icons.first_page), ), Expanded( child: buildSlider(), ), IconButton.filledTonal( - onPressed: context.reader.toNextChapter, + onPressed: () { + if(!context.reader.toNextChapter()) { + context.reader.toPage(context.reader.maxPage); + } + }, icon: const Icon(Icons.last_page)), const SizedBox( width: 8, @@ -407,7 +418,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { switch (showFloatingButtonValue) { case -1: return FloatingActionButton( - onPressed: () => context.reader.toPrevChapter(), + onPressed: () { + setFloatingButton(0); + context.reader.toPrevChapter(); + }, child: const Icon(Icons.arrow_back_ios_outlined), ); case 0: @@ -420,7 +434,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { borderRadius: BorderRadius.circular(16), ), child: Icon( - Icons.arrow_forward_ios, + lastValue == 1 + ? Icons.arrow_forward_ios + : Icons.arrow_back_ios_outlined, size: 24, color: Theme.of(context).colorScheme.onPrimaryContainer, ), @@ -440,7 +456,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { child: Material( color: Colors.transparent, child: InkWell( - onTap: () => context.reader.toNextChapter(), + onTap: () { + setFloatingButton(0); + context.reader.toNextChapter(); + }, borderRadius: BorderRadius.circular(16), child: Center( child: Icon(