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);
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 {

View File

@@ -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(