263 lines
11 KiB
Dart
263 lines
11 KiB
Dart
// ignore_for_file: unnecessary_overrides
|
|
|
|
import 'dart:async';
|
|
import 'package:flutter_guid/flutter_guid.dart';
|
|
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_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:dreampad/app/shared/shared.dart';
|
|
|
|
import '../models/chat_msg_model.dart';
|
|
import '../models/explore_app_model.dart';
|
|
import '../models/knowledge_point_model.dart';
|
|
import '../providers/home_provider.dart';
|
|
import '../widgets/first_time_dialog.dart';
|
|
|
|
class HomeController extends GetxController {
|
|
final HomeProvider homeProvider;
|
|
HomeController({required this.homeProvider});
|
|
final explored = false.obs;
|
|
final create = true.obs;
|
|
final prompt = false.obs;
|
|
final exploreCount = 0.obs;
|
|
final chatMsgList = RxList<ChatMsg>([]);
|
|
final scrollController = ScrollController();
|
|
final selectKnowledge = Rx<KnowledgePoint?>(null);
|
|
final knowledgePoints = RxList<Rx<KnowledgePoint>>([]);
|
|
|
|
late String account = '';
|
|
late int gender = 1;
|
|
late int age = 10;
|
|
|
|
late int occupationId = 1;
|
|
late String occupationName = '画家';
|
|
|
|
late List<ExploreApp> leftExploreApps = [];
|
|
late List<ExploreApp> rightExploreApps = [];
|
|
late List<Goal> goals = [];
|
|
final int second = 3;
|
|
StreamSubscription<dynamic>? subscription;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
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)!;
|
|
create.value = SpUtil.getBool(Constant.create, defValue: true)!;
|
|
initLeftExploreApps();
|
|
initRightExploreApps();
|
|
initArtistGoals();
|
|
initAcademicianGoals();
|
|
initKnowledgePoints();
|
|
if (create.value) {
|
|
subscription = Stream.periodic(const Duration(seconds: 1), (int i) => i)
|
|
.take(second)
|
|
.listen((int i) {
|
|
if (i >= second - 1) {
|
|
create.value = false;
|
|
prompt.value = true;
|
|
SpUtil.putBool(Constant.create, false);
|
|
SmartDialog.show(
|
|
maskColor: const Color(0xFF02184B).withOpacity(0.9),
|
|
onDismiss: () {
|
|
prompt.value = false;
|
|
},
|
|
builder: (_) {
|
|
return const FirstTimeDialog();
|
|
},
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() async {
|
|
super.onReady();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
subscription?.cancel();
|
|
}
|
|
|
|
void initKnowledgePoints() {
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 1, left: 559.0, top: 149.0, title: '钱是怎么形成的?', leared: false)
|
|
.obs);
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 2, right: 751.0, top: 198.0, title: '小实验溶解糖', leared: false)
|
|
.obs);
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 3, left: 632.0, top: 278.0, title: '科学家是怎么工作的?', leared: false)
|
|
.obs);
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 4, left: 814.0, top: 376.0, title: '艺术家——梵高', leared: false)
|
|
.obs);
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 5, right: 696.0, top: 438.0, title: '什么是科学?', leared: false)
|
|
.obs);
|
|
knowledgePoints.add(KnowledgePoint(
|
|
id: 6, left: 741.0, top: 499.0, title: '足球比赛规则', leared: false)
|
|
.obs);
|
|
}
|
|
|
|
void initArtistGoals() {
|
|
goals.add(
|
|
Goal(id: 1, occupationId: 1, age: age + 0, title: '今年目标', contents: [
|
|
GoalContent(title: '基础绘画技巧', content: '学习和练习基础的绘画技巧,如素描、色彩等。'),
|
|
GoalContent(title: '艺术欣赏能力', content: '参观美术馆、画展,增进对不同画派和风格的了解。'),
|
|
GoalContent(title: '创意表达培养', content: '通过日常生活的观察和想象,创作一些个人作品。'),
|
|
]));
|
|
goals.add(
|
|
Goal(id: 2, occupationId: 1, age: age + 3, title: '三年目标', contents: [
|
|
GoalContent(title: '基础绘画技巧', content: '尝试不同的绘画媒介和技巧,开始探索个人的艺术风格。'),
|
|
GoalContent(title: '艺术欣赏能力', content: '参加美术课程或夏令营,系统学习绘画知识。'),
|
|
GoalContent(title: '创意表达培养', content: '参加学校或社区的绘画比赛和展览,锻炼展示自己作品的能力。'),
|
|
]));
|
|
goals.add(Goal(id: 3, occupationId: 1, title: '18岁目标', contents: [
|
|
GoalContent(title: '艺术类院校申请', content: '申请艺术类高中或大学,接受正规的艺术教育。'),
|
|
GoalContent(title: '艺术实践加强', content: '通过参加画展、艺术竞赛等,增加实践经验。'),
|
|
GoalContent(title: '艺术理论学习', content: '学习艺术史、美学等,增强艺术理论素养。'),
|
|
]));
|
|
goals.add(Goal(id: 4, occupationId: 1, title: '22岁目标', contents: [
|
|
GoalContent(title: '专业深造', content: '在艺术类大学深入学习绘画,探索个人艺术方向。'),
|
|
GoalContent(title: '国际视野拓展', content: '参与国际艺术交流活动,了解全球艺术潮流。'),
|
|
GoalContent(title: '独立创作展示', content: '举办个人画展或参加重要艺术展览,展示个人作品。'),
|
|
]));
|
|
goals.add(Goal(id: 5, occupationId: 1, title: '30岁目标', contents: [
|
|
GoalContent(title: '个人品牌建立', content: '作为画家在艺术界建立良好的个人品牌和声誉。'),
|
|
GoalContent(title: '艺术教育贡献', content: '通过教学或工作坊等方式分享艺术知识和技巧。'),
|
|
GoalContent(title: '国际艺术影响力', content: '作品具有国际影响力,参与国际艺术交流与合作。'),
|
|
]));
|
|
}
|
|
|
|
void initAcademicianGoals() {
|
|
goals.add(
|
|
Goal(id: 1, occupationId: 2, age: age + 0, title: '今年目标', contents: [
|
|
GoalContent(title: '课外阅读提升', content: '选择与科学相关的儿童图书,每周至少阅读一本。'),
|
|
GoalContent(title: '科学兴趣培养', content: '参加科学实验兴趣小组或课外科学俱乐部,增进对科学的兴趣和理解。'),
|
|
GoalContent(title: '基础数学能力', content: '每天坚持数学练习,提高逻辑思维和解决问题的能力。'),
|
|
]));
|
|
goals.add(
|
|
Goal(id: 2, occupationId: 2, age: age + 3, title: '三年目标', contents: [
|
|
GoalContent(title: '科学竞赛参与', content: '参加学校或地区的科学竞赛,提高科学实践能力。'),
|
|
GoalContent(title: '英语能力加强', content: '科学领域英语是必备技能,提高英语水平以便阅读国际科学文献。'),
|
|
GoalContent(title: '拓展科学知识', content: '通过在线课程或夏令营等方式,学习物理、化学等更多科学知识。'),
|
|
]));
|
|
goals.add(Goal(id: 3, occupationId: 2, title: '18岁目标', contents: [
|
|
GoalContent(title: '理想大学申请', content: '申请国内外知名大学的科学相关专业,为深造打下基础。'),
|
|
GoalContent(title: '科学研究实习', content: '在大学期间尽早寻找实习机会,加入科研团队。'),
|
|
GoalContent(title: '专业网络构建', content: '建立与科学家和研究人员的联系,拓宽学术交流圈。'),
|
|
]));
|
|
goals.add(Goal(id: 4, occupationId: 2, title: '22岁目标', contents: [
|
|
GoalContent(title: '硕士/博士深造', content: '申请硕士或直接博士项目,深入专业领域研究。'),
|
|
GoalContent(title: '学术论文发表', content: '在专业期刊上发表研究成果,建立学术声誉。'),
|
|
GoalContent(title: '国际科研合作', content: '参与国际科研项目,扩大研究视野。'),
|
|
]));
|
|
goals.add(Goal(id: 5, occupationId: 2, title: '30岁目标', contents: [
|
|
GoalContent(title: '科学研究突破', content: '在某一科学领域取得显著研究成果。'),
|
|
GoalContent(title: '科学社群领导', content: '在科学界承担一定的领导角色,如项目负责人或研究小组领头。'),
|
|
GoalContent(title: '学术影响力拓展', content: '通过公开讲座、论文发表等方式,提高在科学界的影响力。'),
|
|
]));
|
|
}
|
|
|
|
void initLeftExploreApps() {
|
|
leftExploreApps.add(ExploreApp(
|
|
name: '哔哩哔哩',
|
|
icon: 'btn_app_bilibili',
|
|
grayIcon: 'btn_app_bilibili_gray',
|
|
));
|
|
leftExploreApps.add(ExploreApp(
|
|
name: '知乎',
|
|
icon: 'btn_app_zhihu',
|
|
grayIcon: 'btn_app_zhihu_gray',
|
|
));
|
|
leftExploreApps.add(ExploreApp(
|
|
name: '纪念碑谷',
|
|
icon: 'btn_app_jinianbeigu',
|
|
grayIcon: 'btn_app_jinianbeigu_gray',
|
|
));
|
|
leftExploreApps.add(ExploreApp(
|
|
name: '蛋仔派对',
|
|
icon: 'btn_app_danzaipaidui',
|
|
grayIcon: 'btn_app_danzaipaidui_gray',
|
|
));
|
|
}
|
|
|
|
void initRightExploreApps() {
|
|
rightExploreApps.add(ExploreApp(
|
|
name: '古诗文网',
|
|
icon: 'btn_app_gushiwenwang',
|
|
grayIcon: 'btn_app_gushiwenwang_gray',
|
|
));
|
|
rightExploreApps.add(ExploreApp(
|
|
name: '数理思维启蒙',
|
|
icon: 'btn_app_funexpected',
|
|
grayIcon: 'btn_app_funexpected_gray',
|
|
));
|
|
rightExploreApps.add(ExploreApp(
|
|
name: '多邻国',
|
|
icon: 'btn_app_duolingo',
|
|
grayIcon: 'btn_app_duolingo_gray',
|
|
));
|
|
rightExploreApps.add(ExploreApp(
|
|
name: '每日艺术',
|
|
icon: 'btn_app_dailyart',
|
|
grayIcon: 'btn_app_dailyart_gray',
|
|
));
|
|
}
|
|
|
|
Goal getGoal(int id) {
|
|
return goals
|
|
.firstWhere((t) => t.id == id && t.occupationId == occupationId);
|
|
}
|
|
|
|
Future reset() async {
|
|
SpUtil.remove(Constant.create);
|
|
await Get.offAllNamed(Routes.SPLASH);
|
|
}
|
|
|
|
Future leareKnowledge(KnowledgePoint knowledge) async {
|
|
selectKnowledge.value = knowledge;
|
|
chatMsgList.clear();
|
|
chatMsgList.add(ChatMsg(
|
|
id: Guid.newGuid.toString(),
|
|
knowledgeId: knowledge.id,
|
|
isBot: 1,
|
|
text: '探梦者,关于“${knowledge.title}”这个话题,你有什么想法或者疑问? 我们起交流吧!',
|
|
));
|
|
await Get.toNamed(Routes.HOME + Routes.EXPLORE_STUDY);
|
|
}
|
|
|
|
Future addSendMsg(String txt) async {
|
|
var chatMsg = ChatMsg(
|
|
id: Guid.newGuid.toString(),
|
|
text: txt,
|
|
isBot: 0,
|
|
knowledgeId: selectKnowledge.value!.id,
|
|
);
|
|
chatMsgList.add(chatMsg);
|
|
|
|
var knowledge = knowledgePoints
|
|
.firstWhere((t) => t.value.id == selectKnowledge.value!.id);
|
|
knowledge.update((val) {
|
|
val!.leared = true;
|
|
});
|
|
selectKnowledge.update((val) {
|
|
val!.leared = true;
|
|
});
|
|
exploreCount.value++;
|
|
if (exploreCount.value >= 2) {
|
|
explored.value = true;
|
|
}
|
|
}
|
|
}
|