From 2ab22f51e4987e2d19419c55bc97527f24f21917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=85=B1=E5=A4=A9=E5=B0=8F=E7=A6=BD=E5=85=BD?= Date: Tue, 5 Nov 2024 21:52:58 +0800 Subject: [PATCH] read page --- .../pages/read/layout/base/base_layout.dart | 26 ++++++++++--------- lib/src/pages/read/read_page_logic.dart | 21 ++++++++++----- lib/src/pages/read/read_page_state.dart | 4 +-- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/src/pages/read/layout/base/base_layout.dart b/lib/src/pages/read/layout/base/base_layout.dart index 6d857a36..c908367d 100644 --- a/lib/src/pages/read/layout/base/base_layout.dart +++ b/lib/src/pages/read/layout/base/base_layout.dart @@ -48,19 +48,21 @@ abstract class BaseLayout extends StatelessWidget { @override Widget build(BuildContext context) { - if (!readPageState.readyToShow) { - return Center(child: Container(color: UIConfig.readPageBackGroundColor)); - } + return FutureBuilder(future: logic.readPageLogic.delayInitCompleter.future, builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return GetBuilder( + id: BaseLayoutLogic.pageId, + global: false, + init: logic, + builder: (_) => ScrollConfiguration( + behavior: readSetting.showScrollBar.isTrue ? UIConfig.scrollBehaviourWithScrollBarWithMouse : UIConfig.scrollBehaviourWithoutScrollBarWithMouse, + child: buildBody(context), + ), + ); + } - return GetBuilder( - id: BaseLayoutLogic.pageId, - global: false, - init: logic, - builder: (_) => ScrollConfiguration( - behavior: readSetting.showScrollBar.isTrue ? UIConfig.scrollBehaviourWithScrollBarWithMouse : UIConfig.scrollBehaviourWithoutScrollBarWithMouse, - child: buildBody(context), - ), - ); + return Center(child: Container(color: UIConfig.readPageBackGroundColor)); + }); } Widget buildBody(BuildContext context); diff --git a/lib/src/pages/read/read_page_logic.dart b/lib/src/pages/read/read_page_logic.dart index 504969c9..3bfadf54 100644 --- a/lib/src/pages/read/read_page_logic.dart +++ b/lib/src/pages/read/read_page_logic.dart @@ -87,10 +87,19 @@ class ReadPageLogic extends GetxController { final int normalPriority = 10000; + bool inited = false; + Completer delayInitCompleter = Completer(); + @override void onReady() { super.onReady(); + Timer(const Duration(milliseconds: 120), () { + if (inited && !delayInitCompleter.isCompleted) { + delayInitCompleter.complete(); + } + }); + /// Turn page by volume keys. The reason for not use [KeyboardListener]: https://github.com/flutter/flutter/issues/71144 listen2VolumeKeys(); @@ -169,10 +178,10 @@ class ReadPageLogic extends GetxController { (_) => updateSafely([layoutId]), ); - Timer(const Duration(milliseconds: 120), () { - state.readyToShow = true; - updateSafely([layoutId]); - }); + inited = true; + if (!delayInitCompleter.isCompleted) { + delayInitCompleter.complete(); + } } @override @@ -441,7 +450,7 @@ class ReadPageLogic extends GetxController { } void tapLeftRegion() { - if (!state.readyToShow) { + if (!inited) { return; } @@ -461,7 +470,7 @@ class ReadPageLogic extends GetxController { } void tapRightRegion() { - if (!state.readyToShow) { + if (!inited) { return; } if (readSetting.disablePageTurningOnTap.isTrue) { diff --git a/lib/src/pages/read/read_page_state.dart b/lib/src/pages/read/read_page_state.dart index f628ee82..3fbf6c5f 100644 --- a/lib/src/pages/read/read_page_state.dart +++ b/lib/src/pages/read/read_page_state.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:battery_plus/battery_plus.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -21,8 +23,6 @@ class ReadPageState with ScrollStatusListerState { late List thumbnails; late List images; - bool readyToShow = false; - late List parseImageHrefsStates; late List parseImageUrlStates; late List imageContainerSizes;