From 3b66a0bea1cbf8f38f3247d7e0254b8e489ffd42 Mon Sep 17 00:00:00 2001 From: tanghong668 <13926187239@163.com> Date: Thu, 30 Nov 2023 01:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=87=AA=E7=94=B1=E6=8E=A2?= =?UTF-8?q?=E7=B4=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/controllers/home_controller.dart | 56 ++++++++++++++++--- lib/app/modules/home/views/home_view.dart | 8 ++- .../modules/home/widgets/explore_widget.dart | 39 +++++++++---- 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/lib/app/modules/home/controllers/home_controller.dart b/lib/app/modules/home/controllers/home_controller.dart index d9a59a5..174b3f7 100644 --- a/lib/app/modules/home/controllers/home_controller.dart +++ b/lib/app/modules/home/controllers/home_controller.dart @@ -7,7 +7,6 @@ import 'package:dreampad/app/models/models.dart'; import 'package:dreampad/app/routes/app_pages.dart'; import 'package:flustars_flutter3/flustars_flutter3.dart'; import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:dreampad/app/shared/shared.dart'; @@ -24,17 +23,19 @@ class HomeController extends GetxController { HomeController({required this.homeProvider}); - final explored = false.obs; + final explored = true.obs; final explored2 = 0.obs; final create = true.obs; final prompt = false.obs; - final exploreCount = 0.obs; + final exploreCount = 2.obs; final exploreDay = 1.obs; final chatMsgList = RxList([]); final selectKnowledge = Rx(null); final knowledgePoints = RxList>([]); final knowledgePointDialogues = RxList([]); final chatInputMsg = ''.obs; + final remainTimeStr = '45:00'.obs; + final availableApp = false.obs; late String account = '琉璃'; late int gender = 1; @@ -51,14 +52,17 @@ class HomeController extends GetxController { StreamSubscription? subscription; final scrollController = ScrollController(); late TextEditingController textController = TextEditingController(); + Timer? exploreTimer; + late int countTime = 45 * 60; + final repeatPeriod = const Duration(seconds: 1); @override void onInit() { super.onInit(); - // account = SpUtil.getString(Constant.account).nullSafe; + account = SpUtil.getString(Constant.account).nullSafe; gender = SpUtil.getInt(Constant.gender, defValue: 1)!; age = SpUtil.getInt(Constant.age, defValue: 10)!; - // occupationName = SpUtil.getString(Constant.occupationName).nullSafe; - // occupationId = SpUtil.getInt(Constant.occupationId, defValue: 2)!; + occupationName = SpUtil.getString(Constant.occupationName).nullSafe; + occupationId = SpUtil.getInt(Constant.occupationId, defValue: 2)!; create.value = SpUtil.getBool(Constant.create, defValue: true)!; initLeftExploreApps(); initRightExploreApps(); @@ -95,6 +99,44 @@ class HomeController extends GetxController { super.onClose(); textController.dispose(); subscription?.cancel(); + exploreTimer?.cancel(); + } + + Future explorePress() async { + if (explored.value) { + availableApp.value = true; + if (exploreTimer == null) { + exploreTimer = Timer.periodic(repeatPeriod, (timer) { + if (countTime <= 0) { + explored.value = false; + exploreCount.value = 0; + availableApp.value = false; + countTime = 45 * 60; + exploreTimer!.cancel(); + exploreTimer = null; + return; + } + countTime--; + int minute = countTime % 3600 ~/ 60; + int second = countTime % 60; + var str = ''; + if (minute / 10 < 1) { + str = '${str}0$minute:'; + } else { + str = '$str$minute:'; + } + if (second / 10 < 1) { + str = '${str}0$second'; + } else { + str = '$str$second'; + } + remainTimeStr.value = str; + }); + } else { + exploreTimer!.cancel(); + exploreTimer = null; + } + } } void initKnowledgePoints() { @@ -494,7 +536,7 @@ class HomeController extends GetxController { knowledgeId: selectKnowledge.value!.id, ); chatMsgList.add(chatMsg); - + sendCount++; knowledgePointDialogue = knowledgePointDialogues.firstWhere((t) => t!.kpId == selectKnowledge.value!.id && t.id == sendCount && !t.isGpt!); diff --git a/lib/app/modules/home/views/home_view.dart b/lib/app/modules/home/views/home_view.dart index 5435e0a..75d8748 100644 --- a/lib/app/modules/home/views/home_view.dart +++ b/lib/app/modules/home/views/home_view.dart @@ -109,6 +109,10 @@ class HomeView extends GetView { child: ExploreWidget( explored: controller.explored.value, exploreCount: controller.exploreCount.value, + remainTime: controller.remainTimeStr.value, + onPressed: () async { + controller.explorePress(); + }, ), ), controller.prompt.value @@ -630,13 +634,13 @@ class HomeView extends GetView { Widget exploreAppWidget(ExploreApp app) { return GestureDetector( onTap: () { - if (controller.explored.value) {} + if (controller.availableApp.value) {} }, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ LoadAssetImage( - 'home/${controller.explored.value ? app.icon : app.grayIcon}', + 'home/${controller.availableApp.value ? app.icon : app.grayIcon}', height: 74.w, width: 74.w, fit: BoxFit.fill, diff --git a/lib/app/modules/home/widgets/explore_widget.dart b/lib/app/modules/home/widgets/explore_widget.dart index 16ea91f..2ebfe6b 100644 --- a/lib/app/modules/home/widgets/explore_widget.dart +++ b/lib/app/modules/home/widgets/explore_widget.dart @@ -1,17 +1,25 @@ import 'package:dreampad/app/shared/shared.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:get/get.dart'; -class ExploreWidget extends GetView { +class ExploreWidget extends StatefulWidget { const ExploreWidget({ super.key, required this.explored, required this.exploreCount, + this.onPressed, + this.remainTime, }); final bool explored; final int exploreCount; + final String? remainTime; + final VoidCallback? onPressed; + @override + State createState() => _ExploreWidgetState(); +} +class _ExploreWidgetState extends State { + late bool suspend = false; @override Widget build(BuildContext context) { return Container( @@ -19,7 +27,9 @@ class ExploreWidget extends GetView { width: 201.w, decoration: BoxDecoration( image: DecorationImage( - image: explored ? Images.homeExplorePre : Images.homeExploreDefault, + image: widget.explored + ? Images.homeExplorePre + : Images.homeExploreDefault, fit: BoxFit.fill, ), ), @@ -28,9 +38,18 @@ class ExploreWidget extends GetView { const RSizedBox(width: 10.0), GestureDetector( onTap: () { - if (explored) {} + if (widget.explored) { + setState(() { + suspend = !suspend; + }); + widget.onPressed?.call(); + } }, - child: explored ? Images.homeExploreBegin : Images.homeBeginGray, + child: widget.explored + ? suspend + ? Images.homeExploreCountdown + : Images.homeExploreBegin + : Images.homeBeginGray, ), Column( mainAxisAlignment: MainAxisAlignment.center, @@ -38,23 +57,23 @@ class ExploreWidget extends GetView { children: [ Text( '自由探索', - style: explored + style: widget.explored ? TextStyles.boldWhiteShadow22_101 : TextStyles.boldWhiteShadow22_100, ), const RSizedBox(height: 4.0), - explored + widget.explored ? Text( - '剩余时间:45:00', + '剩余时间:${widget.remainTime}', style: TextStyles.mediumWhiteShadow14_101, ) : Row( children: [ - exploreCount == 0 + widget.exploreCount == 0 ? Images.homeProgressBar : Images.homeProgressBarIn, const RSizedBox(width: 1.0), - exploreCount >= 2 + widget.exploreCount >= 2 ? Images.homeProgressBarIn : Images.homeProgressBar, ],