Skip to content

Commit

Permalink
fixbug keep loading
Browse files Browse the repository at this point in the history
  • Loading branch information
LEHOANGLONG0807 committed Feb 14, 2022
1 parent 29d311e commit ddd854e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
18 changes: 9 additions & 9 deletions lib/pages/home/widget/page_view_story_in_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PageViewStoryInGroup extends StatelessWidget {
}).toList(),
),
),
_buildRowStep(),
// _buildRowStep(),
],
);
}
Expand All @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions lib/pages/read_story/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/read_story/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import 'widget/widget.dart';

import 'controller.dart';

class ReadStoryPage extends GetView<ReadStoryController> {
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(
Expand Down Expand Up @@ -58,9 +60,9 @@ class ReadStoryPage extends GetView<ReadStoryController> {
);
}),
drawer: Drawer(
child: ContainerDrawer(),
child: ContainerDrawer(controller),
).wrapWidth(Get.width * 0.9),
bottomNavigationBar: ContainerBottomReadAction(),
bottomNavigationBar: ContainerBottomReadAction(controller),
),
);
}
Expand Down
15 changes: 9 additions & 6 deletions lib/pages/read_story/widget/container_bottom_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import '../../../common/common.dart';
import '../../pages.dart';

class ContainerBottomReadAction extends StatelessWidget {
final _controller = Get.find<ReadStoryController>();
final ReadStoryController controller;

ContainerBottomReadAction(this.controller);

final _theme = Get.theme;
@override
Widget build(BuildContext context) {
return Obx(
() => 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(
Expand All @@ -25,7 +28,7 @@ class ContainerBottomReadAction extends StatelessWidget {
Column(
children: [
InkWell(
onTap: _controller.onTapChapterPre,
onTap: controller.onTapChapterPre,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -39,7 +42,7 @@ class ContainerBottomReadAction extends StatelessWidget {
),
20.verticalSpace,
InkWell(
onTap: _controller.onTapListChapter,
onTap: controller.onTapListChapter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -56,7 +59,7 @@ class ContainerBottomReadAction extends StatelessWidget {
Column(
children: [
InkWell(
onTap: _controller.onTapChapterNext,
onTap: controller.onTapChapterNext,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -70,7 +73,7 @@ class ContainerBottomReadAction extends StatelessWidget {
),
20.verticalSpace,
InkWell(
onTap: _controller.onTapSetting,
onTap: controller.onTapSetting,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down
31 changes: 17 additions & 14 deletions lib/pages/read_story/widget/container_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import '../../../common/common.dart';
import '../../pages.dart';

class ContainerDrawer extends StatelessWidget {
final _controller = Get.find<ReadStoryController>();
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,
Expand All @@ -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),
);
Expand Down Expand Up @@ -89,7 +92,7 @@ class ContainerDrawer extends StatelessWidget {

Widget _buildContainerStory() {
return InkWell(
onTap: _controller.onTapDetailStory,
onTap: controller.onTapDetailStory,
child: Row(
children: [
_buildImage(),
Expand All @@ -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,
Expand All @@ -130,7 +133,7 @@ class ContainerDrawer extends StatelessWidget {
borderRadius: BorderRadius.circular(4),
),
child: CachedImageNetworkWidget(
url: _controller.storyModel?.thumbnail ?? '',
url: controller.storyModel?.thumbnail ?? '',
),
);
}
Expand All @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions lib/routes/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
],
),
];
}

0 comments on commit ddd854e

Please sign in to comment.