From ddd854eb0a2434b00bb79f230db31fbbce758600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Ho=C3=A0ng=20Long?= <58676739+LEHOANGLONG1999@users.noreply.github.com> Date: Mon, 14 Feb 2022 18:32:39 +0700 Subject: [PATCH] fixbug keep loading --- .../home/widget/page_view_story_in_group.dart | 18 +++++------ lib/pages/read_story/controller.dart | 20 ++++++------ lib/pages/read_story/page.dart | 8 +++-- .../widget/container_bottom_action.dart | 15 +++++---- .../read_story/widget/container_drawer.dart | 31 ++++++++++--------- lib/routes/app_pages.dart | 9 +++--- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/lib/pages/home/widget/page_view_story_in_group.dart b/lib/pages/home/widget/page_view_story_in_group.dart index 7a3e82c..2d70679 100644 --- a/lib/pages/home/widget/page_view_story_in_group.dart +++ b/lib/pages/home/widget/page_view_story_in_group.dart @@ -42,7 +42,7 @@ class PageViewStoryInGroup extends StatelessWidget { }).toList(), ), ), - _buildRowStep(), + // _buildRowStep(), ], ); } @@ -64,14 +64,14 @@ class PageViewStoryInGroup extends StatelessWidget { }).toList()); } - Widget _buildRowStep() { - return Obx( - () => Row( - mainAxisAlignment: MainAxisAlignment.center, - children: _numberPage.asMap().keys.map((e) => _buildItemStep(isFocus: e < _currentIndexPage.value + 0.4 && e > _currentIndexPage.value - 0.6)).toList(), - ), - ); - } + // Widget _buildRowStep() { + // return Obx( + // () => Row( + // mainAxisAlignment: MainAxisAlignment.center, + // children: _numberPage.asMap().keys.map((e) => _buildItemStep(isFocus: e < _currentIndexPage.value + 0.4 && e > _currentIndexPage.value - 0.6)).toList(), + // ), + // ); + // } Widget _buildItemStep({bool isFocus = false}) { return Container( diff --git a/lib/pages/read_story/controller.dart b/lib/pages/read_story/controller.dart index d03b684..8bd2b7d 100644 --- a/lib/pages/read_story/controller.dart +++ b/lib/pages/read_story/controller.dart @@ -20,14 +20,11 @@ import '../../services/services.dart'; import 'setting_read_page.dart'; class ReadStoryController extends GetxController { - final ChapterRepositoryImpl chapterRepository; + ChapterRepositoryImpl get chapterRepository => Get.find(); - final StoryRepositoryImpl storyRepository; + StoryRepositoryImpl get storyRepository => Get.find(); - final DBService dbService; - - ReadStoryController( - {required this.chapterRepository, required this.storyRepository, required this.dbService}); + DBService get dbService => Get.find(); AppController get appController => Get.find(); @@ -134,10 +131,12 @@ class ReadStoryController extends GetxController { Future fetchChapterContentById() async { try { EasyLoading.show(); - appController.bannerAdMedium.dispose(); - appController.bannerAdMedium.load(); - appController.bannerAdMedium2.dispose(); - appController.bannerAdMedium2.load(); + if (appController.showAds) { + appController.bannerAdMedium.dispose(); + appController.bannerAdMedium.load(); + appController.bannerAdMedium2.dispose(); + appController.bannerAdMedium2.load(); + } final _response = await chapterRepository.fetchChapterContentById(chapterId: chapterId, storyId: storyId); chapterContentModel.value = _response; @@ -230,6 +229,7 @@ class ReadStoryController extends GetxController { EasyLoading.show(); final _boardLocalModel = storyModel!.toStoryBroadLocalModel; final _response = await dbService.addStoryBoard(model: _boardLocalModel); + EasyLoading.dismiss(); if (_response) { showSnackBarSuccess(message: 'Thêm vào tủ truyện thành công!'); showButtonAddBoard.value = false; diff --git a/lib/pages/read_story/page.dart b/lib/pages/read_story/page.dart index 2a2aff7..241e6de 100644 --- a/lib/pages/read_story/page.dart +++ b/lib/pages/read_story/page.dart @@ -9,8 +9,10 @@ import 'widget/widget.dart'; import 'controller.dart'; -class ReadStoryPage extends GetView { +class ReadStoryPage extends StatelessWidget { final _theme = Get.theme; + final controller = Get.put(ReadStoryController(), + tag: '${Get.arguments?['storyId'] ?? ''}-${Get.arguments?['chapterId'] ?? ''}'); @override Widget build(BuildContext context) { return WillPopScope( @@ -58,9 +60,9 @@ class ReadStoryPage extends GetView { ); }), drawer: Drawer( - child: ContainerDrawer(), + child: ContainerDrawer(controller), ).wrapWidth(Get.width * 0.9), - bottomNavigationBar: ContainerBottomReadAction(), + bottomNavigationBar: ContainerBottomReadAction(controller), ), ); } diff --git a/lib/pages/read_story/widget/container_bottom_action.dart b/lib/pages/read_story/widget/container_bottom_action.dart index 0f4c330..67c6e61 100644 --- a/lib/pages/read_story/widget/container_bottom_action.dart +++ b/lib/pages/read_story/widget/container_bottom_action.dart @@ -6,7 +6,10 @@ import '../../../common/common.dart'; import '../../pages.dart'; class ContainerBottomReadAction extends StatelessWidget { - final _controller = Get.find(); + final ReadStoryController controller; + + ContainerBottomReadAction(this.controller); + final _theme = Get.theme; @override Widget build(BuildContext context) { @@ -14,7 +17,7 @@ class ContainerBottomReadAction extends StatelessWidget { () => AnimatedContainer( duration: 250.milliseconds, width: double.infinity, - height: _controller.showAction.value ? 130 : 0, + height: controller.showAction.value ? 130 : 0, padding: UIHelper.paddingAll16, color: AssetColors.colorGreyE7E7E7, child: SingleChildScrollView( @@ -25,7 +28,7 @@ class ContainerBottomReadAction extends StatelessWidget { Column( children: [ InkWell( - onTap: _controller.onTapChapterPre, + onTap: controller.onTapChapterPre, child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -39,7 +42,7 @@ class ContainerBottomReadAction extends StatelessWidget { ), 20.verticalSpace, InkWell( - onTap: _controller.onTapListChapter, + onTap: controller.onTapListChapter, child: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -56,7 +59,7 @@ class ContainerBottomReadAction extends StatelessWidget { Column( children: [ InkWell( - onTap: _controller.onTapChapterNext, + onTap: controller.onTapChapterNext, child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -70,7 +73,7 @@ class ContainerBottomReadAction extends StatelessWidget { ), 20.verticalSpace, InkWell( - onTap: _controller.onTapSetting, + onTap: controller.onTapSetting, child: Column( mainAxisSize: MainAxisSize.min, children: [ diff --git a/lib/pages/read_story/widget/container_drawer.dart b/lib/pages/read_story/widget/container_drawer.dart index 9d3f17d..e0a8642 100644 --- a/lib/pages/read_story/widget/container_drawer.dart +++ b/lib/pages/read_story/widget/container_drawer.dart @@ -6,16 +6,19 @@ import '../../../common/common.dart'; import '../../pages.dart'; class ContainerDrawer extends StatelessWidget { - final _controller = Get.find(); + final ReadStoryController controller; + + ContainerDrawer(this.controller); + ScrollController? _scrollController; final _theme = Get.theme; @override Widget build(BuildContext context) { - if (_controller.reverseChapterList.value) { - _scrollController = ScrollController(initialScrollOffset: _controller.chapterContentModel.value.id * 60 - Get.height / 2); + if (controller.reverseChapterList.value) { + _scrollController = ScrollController(initialScrollOffset: controller.chapterContentModel.value.id * 60 - Get.height / 2); } else { _scrollController = - ScrollController(initialScrollOffset: (_controller.allChapters.length - _controller.chapterContentModel.value.id) * 60 - Get.height / 2); + ScrollController(initialScrollOffset: (controller.allChapters.length - controller.chapterContentModel.value.id) * 60 - Get.height / 2); } return Container( width: double.infinity, @@ -38,15 +41,15 @@ class ContainerDrawer extends StatelessWidget { controller: _scrollController, padding: const EdgeInsets.only(left: 10), itemBuilder: (_, index) { - final _chapterTitle = _controller.allChapters[index]; - final _idChapterSelected = _controller.chapterContentModel.value.id; + final _chapterTitle = controller.allChapters[index]; + final _idChapterSelected = controller.chapterContentModel.value.id; return _buildItemChapter( title: _chapterTitle.chapTitle ?? '', isSelected: _chapterTitle.id == _idChapterSelected, - onTap: () => _controller.onTapChooseChapter(_chapterTitle.id), + onTap: () => controller.onTapChooseChapter(_chapterTitle.id), ); }, - itemCount: _controller.allChapters.length, + itemCount: controller.allChapters.length, separatorBuilder: (_, int index) => const Divider(height: 0), ).scrollBar(color: Colors.black, controller: _scrollController), ); @@ -89,7 +92,7 @@ class ContainerDrawer extends StatelessWidget { Widget _buildContainerStory() { return InkWell( - onTap: _controller.onTapDetailStory, + onTap: controller.onTapDetailStory, child: Row( children: [ _buildImage(), @@ -107,11 +110,11 @@ class ContainerDrawer extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '${_controller.storyModel?.chap ?? 0} chương - ${(_controller.storyModel?.isFull ?? false) ? 'Hoàn thành' : 'Đang ra'}', + '${controller.storyModel?.chap ?? 0} chương - ${(controller.storyModel?.isFull ?? false) ? 'Hoàn thành' : 'Đang ra'}', style: _theme.textTheme.subtitle1!.regular.textWhite, ), InkWell( - onTap: _controller.onTapSortChapter, + onTap: controller.onTapSortChapter, child: Text( 'Đảo thứ tự', style: _theme.textTheme.subtitle1!.textWhite, @@ -130,7 +133,7 @@ class ContainerDrawer extends StatelessWidget { borderRadius: BorderRadius.circular(4), ), child: CachedImageNetworkWidget( - url: _controller.storyModel?.thumbnail ?? '', + url: controller.storyModel?.thumbnail ?? '', ), ); } @@ -142,14 +145,14 @@ class ContainerDrawer extends StatelessWidget { children: [ Row(), Text( - _controller.storyModel?.title ?? '', + controller.storyModel?.title ?? '', maxLines: 3, overflow: TextOverflow.ellipsis, style: _theme.textTheme.subtitle1!.textWhite.size(18).semiBold.heightLine(20), ), 10.horizontalSpace, Text( - _controller.storyModel?.authorName ?? '', + controller.storyModel?.authorName ?? '', maxLines: 1, overflow: TextOverflow.ellipsis, style: _theme.textTheme.subtitle1!.regular.textWhite, diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index 970fcf0..f9b08fb 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -60,22 +60,21 @@ abstract class AppPages { name: Routes.SEARCH, page: () => SearchPage(), bindings: [ - BindingsBuilder.put(() => SearchController(searchRepository: Get.find(), homeRepository: Get.find())), + BindingsBuilder.put( + () => SearchController(searchRepository: Get.find(), homeRepository: Get.find())), ], ), GetPage( name: Routes.DETAIL_STORY, page: () => DetailStoryPage(), bindings: [ - BindingsBuilder.put(() => DetailStoryController(storyRepository: Get.find(), chapterRepository: Get.find(), dbService: Get.find())), + BindingsBuilder.put(() => DetailStoryController( + storyRepository: Get.find(), chapterRepository: Get.find(), dbService: Get.find())), ], ), GetPage( name: Routes.READING_STORY, page: () => ReadStoryPage(), - bindings: [ - BindingsBuilder.put(() => ReadStoryController(chapterRepository: Get.find(), storyRepository: Get.find(), dbService: Get.find())), - ], ), ]; }