完善自由探索逻辑

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: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<ChatMsg>([]);
final selectKnowledge = Rx<KnowledgePoint?>(null);
final knowledgePoints = RxList<Rx<KnowledgePoint>>([]);
final knowledgePointDialogues = RxList<KnowledgePointDialogue?>([]);
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<dynamic>? 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() {

View File

@ -109,6 +109,10 @@ class HomeView extends GetView<HomeController> {
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<HomeController> {
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,

View File

@ -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<ExploreWidget> createState() => _ExploreWidgetState();
}
class _ExploreWidgetState extends State<ExploreWidget> {
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,
],