improve reader

This commit is contained in:
nyne
2024-10-30 10:13:30 +08:00
parent 02bda275b1
commit 363f3641fb
2 changed files with 35 additions and 13 deletions

View File

@@ -116,6 +116,9 @@ class _GalleryModeState extends State<_GalleryMode>
controller = PageController(initialPage: reader.page); controller = PageController(initialPage: reader.page);
reader._imageViewController = this; reader._imageViewController = this;
cached = List.filled(reader.maxPage + 2, false); cached = List.filled(reader.maxPage + 2, false);
Future.microtask(() {
context.readerScaffold.setFloatingButton(0);
});
super.initState(); super.initState();
} }
@@ -180,11 +183,11 @@ class _GalleryModeState extends State<_GalleryMode>
), ),
onPageChanged: (i) { onPageChanged: (i) {
if (i == 0) { if (i == 0) {
if (!reader.toNextChapter()) { if (!reader.toPrevChapter()) {
reader.toPage(1); reader.toPage(1);
} }
} else if (i == reader.maxPage + 1) { } else if (i == reader.maxPage + 1) {
if (!reader.toPrevChapter()) { if (!reader.toNextChapter()) {
reader.toPage(reader.maxPage); reader.toPage(reader.maxPage);
} }
} else { } else {

View File

@@ -20,9 +20,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
int showFloatingButtonValue = 0; int showFloatingButtonValue = 0;
var lastValue = 0;
double fABValue = 0; double fABValue = 0;
void setFloatingButton(int value) { void setFloatingButton(int value) {
lastValue = showFloatingButtonValue;
if (value == 0) { if (value == 0) {
if (showFloatingButtonValue != 0) { if (showFloatingButtonValue != 0) {
showFloatingButtonValue = 0; showFloatingButtonValue = 0;
@@ -79,6 +82,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
child: widget.child, child: widget.child,
), ),
buildPageInfoText(), buildPageInfoText(),
AnimatedPositioned(
duration: const Duration(milliseconds: 180),
right: 16,
bottom: showFloatingButtonValue == 0 ? -58 : 16,
child: buildEpChangeButton(),
),
AnimatedPositioned( AnimatedPositioned(
duration: const Duration(milliseconds: 180), duration: const Duration(milliseconds: 180),
top: _isOpen ? 0 : -(kTopBarHeight + context.padding.top), top: _isOpen ? 0 : -(kTopBarHeight + context.padding.top),
@@ -95,12 +104,6 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
height: kBottomBarHeight + context.padding.bottom, height: kBottomBarHeight + context.padding.bottom,
child: buildBottom(), 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: [ children: [
const SizedBox(width: 8), const SizedBox(width: 8),
IconButton.filledTonal( IconButton.filledTonal(
onPressed: context.reader.toPrevChapter, onPressed: () {
if(!context.reader.toPrevChapter()) {
context.reader.toPage(1);
}
},
icon: const Icon(Icons.first_page), icon: const Icon(Icons.first_page),
), ),
Expanded( Expanded(
child: buildSlider(), child: buildSlider(),
), ),
IconButton.filledTonal( IconButton.filledTonal(
onPressed: context.reader.toNextChapter, onPressed: () {
if(!context.reader.toNextChapter()) {
context.reader.toPage(context.reader.maxPage);
}
},
icon: const Icon(Icons.last_page)), icon: const Icon(Icons.last_page)),
const SizedBox( const SizedBox(
width: 8, width: 8,
@@ -407,7 +418,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
switch (showFloatingButtonValue) { switch (showFloatingButtonValue) {
case -1: case -1:
return FloatingActionButton( return FloatingActionButton(
onPressed: () => context.reader.toPrevChapter(), onPressed: () {
setFloatingButton(0);
context.reader.toPrevChapter();
},
child: const Icon(Icons.arrow_back_ios_outlined), child: const Icon(Icons.arrow_back_ios_outlined),
); );
case 0: case 0:
@@ -420,7 +434,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
), ),
child: Icon( child: Icon(
Icons.arrow_forward_ios, lastValue == 1
? Icons.arrow_forward_ios
: Icons.arrow_back_ios_outlined,
size: 24, size: 24,
color: Theme.of(context).colorScheme.onPrimaryContainer, color: Theme.of(context).colorScheme.onPrimaryContainer,
), ),
@@ -440,7 +456,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
onTap: () => context.reader.toNextChapter(), onTap: () {
setFloatingButton(0);
context.reader.toNextChapter();
},
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
child: Center( child: Center(
child: Icon( child: Icon(