完善自由探索逻辑

This commit is contained in:
tanghong668 2023-11-30 01:11:31 +08:00
parent 3202fe4733
commit 3b66a0bea1
3 changed files with 84 additions and 19 deletions

View File

@ -7,7 +7,6 @@ import 'package:dreampad/app/models/models.dart';
import 'package:dreampad/app/routes/app_pages.dart'; import 'package:dreampad/app/routes/app_pages.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart'; import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:dreampad/app/shared/shared.dart'; import 'package:dreampad/app/shared/shared.dart';
@ -24,17 +23,19 @@ class HomeController extends GetxController {
HomeController({required this.homeProvider}); HomeController({required this.homeProvider});
final explored = false.obs; final explored = true.obs;
final explored2 = 0.obs; final explored2 = 0.obs;
final create = true.obs; final create = true.obs;
final prompt = false.obs; final prompt = false.obs;
final exploreCount = 0.obs; final exploreCount = 2.obs;
final exploreDay = 1.obs; final exploreDay = 1.obs;
final chatMsgList = RxList<ChatMsg>([]); final chatMsgList = RxList<ChatMsg>([]);
final selectKnowledge = Rx<KnowledgePoint?>(null); final selectKnowledge = Rx<KnowledgePoint?>(null);
final knowledgePoints = RxList<Rx<KnowledgePoint>>([]); final knowledgePoints = RxList<Rx<KnowledgePoint>>([]);
final knowledgePointDialogues = RxList<KnowledgePointDialogue?>([]); final knowledgePointDialogues = RxList<KnowledgePointDialogue?>([]);
final chatInputMsg = ''.obs; final chatInputMsg = ''.obs;
final remainTimeStr = '45:00'.obs;
final availableApp = false.obs;
late String account = '琉璃'; late String account = '琉璃';
late int gender = 1; late int gender = 1;
@ -51,14 +52,17 @@ class HomeController extends GetxController {
StreamSubscription<dynamic>? subscription; StreamSubscription<dynamic>? subscription;
final scrollController = ScrollController(); final scrollController = ScrollController();
late TextEditingController textController = TextEditingController(); late TextEditingController textController = TextEditingController();
Timer? exploreTimer;
late int countTime = 45 * 60;
final repeatPeriod = const Duration(seconds: 1);
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
// account = SpUtil.getString(Constant.account).nullSafe; account = SpUtil.getString(Constant.account).nullSafe;
gender = SpUtil.getInt(Constant.gender, defValue: 1)!; gender = SpUtil.getInt(Constant.gender, defValue: 1)!;
age = SpUtil.getInt(Constant.age, defValue: 10)!; age = SpUtil.getInt(Constant.age, defValue: 10)!;
// occupationName = SpUtil.getString(Constant.occupationName).nullSafe; occupationName = SpUtil.getString(Constant.occupationName).nullSafe;
// occupationId = SpUtil.getInt(Constant.occupationId, defValue: 2)!; occupationId = SpUtil.getInt(Constant.occupationId, defValue: 2)!;
create.value = SpUtil.getBool(Constant.create, defValue: true)!; create.value = SpUtil.getBool(Constant.create, defValue: true)!;
initLeftExploreApps(); initLeftExploreApps();
initRightExploreApps(); initRightExploreApps();
@ -95,6 +99,44 @@ class HomeController extends GetxController {
super.onClose(); super.onClose();
textController.dispose(); textController.dispose();
subscription?.cancel(); 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() { void initKnowledgePoints() {

View File

@ -109,6 +109,10 @@ class HomeView extends GetView<HomeController> {
child: ExploreWidget( child: ExploreWidget(
explored: controller.explored.value, explored: controller.explored.value,
exploreCount: controller.exploreCount.value, exploreCount: controller.exploreCount.value,
remainTime: controller.remainTimeStr.value,
onPressed: () async {
controller.explorePress();
},
), ),
), ),
controller.prompt.value controller.prompt.value
@ -630,13 +634,13 @@ class HomeView extends GetView<HomeController> {
Widget exploreAppWidget(ExploreApp app) { Widget exploreAppWidget(ExploreApp app) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
if (controller.explored.value) {} if (controller.availableApp.value) {}
}, },
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
LoadAssetImage( LoadAssetImage(
'home/${controller.explored.value ? app.icon : app.grayIcon}', 'home/${controller.availableApp.value ? app.icon : app.grayIcon}',
height: 74.w, height: 74.w,
width: 74.w, width: 74.w,
fit: BoxFit.fill, fit: BoxFit.fill,

View File

@ -1,17 +1,25 @@
import 'package:dreampad/app/shared/shared.dart'; import 'package:dreampad/app/shared/shared.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class ExploreWidget extends GetView { class ExploreWidget extends StatefulWidget {
const ExploreWidget({ const ExploreWidget({
super.key, super.key,
required this.explored, required this.explored,
required this.exploreCount, required this.exploreCount,
this.onPressed,
this.remainTime,
}); });
final bool explored; final bool explored;
final int exploreCount; final int exploreCount;
final String? remainTime;
final VoidCallback? onPressed;
@override
State<ExploreWidget> createState() => _ExploreWidgetState();
}
class _ExploreWidgetState extends State<ExploreWidget> {
late bool suspend = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -19,7 +27,9 @@ class ExploreWidget extends GetView {
width: 201.w, width: 201.w,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: explored ? Images.homeExplorePre : Images.homeExploreDefault, image: widget.explored
? Images.homeExplorePre
: Images.homeExploreDefault,
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
), ),
@ -28,9 +38,18 @@ class ExploreWidget extends GetView {
const RSizedBox(width: 10.0), const RSizedBox(width: 10.0),
GestureDetector( GestureDetector(
onTap: () { 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( Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -38,23 +57,23 @@ class ExploreWidget extends GetView {
children: [ children: [
Text( Text(
'自由探索', '自由探索',
style: explored style: widget.explored
? TextStyles.boldWhiteShadow22_101 ? TextStyles.boldWhiteShadow22_101
: TextStyles.boldWhiteShadow22_100, : TextStyles.boldWhiteShadow22_100,
), ),
const RSizedBox(height: 4.0), const RSizedBox(height: 4.0),
explored widget.explored
? Text( ? Text(
'剩余时间:45:00', '剩余时间:${widget.remainTime}',
style: TextStyles.mediumWhiteShadow14_101, style: TextStyles.mediumWhiteShadow14_101,
) )
: Row( : Row(
children: [ children: [
exploreCount == 0 widget.exploreCount == 0
? Images.homeProgressBar ? Images.homeProgressBar
: Images.homeProgressBarIn, : Images.homeProgressBarIn,
const RSizedBox(width: 1.0), const RSizedBox(width: 1.0),
exploreCount >= 2 widget.exploreCount >= 2
? Images.homeProgressBarIn ? Images.homeProgressBarIn
: Images.homeProgressBar, : Images.homeProgressBar,
], ],