dreampad/lib/app/modules/home/views/explore_study_view.dart

155 lines
4.8 KiB
Dart
Raw Normal View History

2023-11-28 10:44:58 +08:00
import 'package:dreampad/app/modules/home/models/chat_msg_model.dart';
import 'package:dreampad/app/shared/shared.dart';
import 'package:flutter/material.dart';
2023-11-28 20:25:09 +08:00
import 'package:flutter_hooks/flutter_hooks.dart';
2023-11-28 10:44:58 +08:00
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/home_controller.dart';
import '../widgets/chat_input_widget.dart';
import '../widgets/receive_message_widget.dart';
import '../widgets/send_message_widget.dart';
class ExploreStudyView extends GetView<HomeController> {
const ExploreStudyView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: Images.studyKnowledgeBg,
fit: BoxFit.fill,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
body: buildBody(context),
),
),
);
}
Widget buildBody(BuildContext context) {
2023-11-30 00:08:39 +08:00
return Obx(
() => Column(
mainAxisSize: MainAxisSize.max,
children: [
const RSizedBox(height: 22.0),
Container(
height: 78.h,
padding: REdgeInsets.symmetric(horizontal: 20.0, vertical: 12.0),
child: Stack(
children: [
MyBackButton(
onPressed: () {
Get.back();
},
2023-11-28 10:44:58 +08:00
),
2023-11-30 00:08:39 +08:00
Center(
child: Text(
controller.selectKnowledge.value!.title!,
style: TextStyles.boldWhiteShadow34_200,
),
)
],
),
2023-11-28 10:44:58 +08:00
),
2023-11-30 00:08:39 +08:00
const RSizedBox(height: 10.0),
Row(
2023-11-28 15:44:41 +08:00
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 214.w,
height: 63.h,
decoration: BoxDecoration(
image: DecorationImage(
image: controller.selectKnowledge.value!.leared!
? Images.studyKnowledgePre
: Images.studyKnowledgeDefault,
fit: BoxFit.fill,
2023-11-28 10:44:58 +08:00
),
2023-11-28 15:44:41 +08:00
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
controller.selectKnowledge.value!.leared!
? Images.studyIllumePre
: Images.studyIllumeDefault,
const RSizedBox(width: 4.0),
Text(
controller.selectKnowledge.value!.leared!
? '已点亮知识点'
: '点亮知识点',
style: TextStyles.mediumWhite20,
),
],
),
)
],
),
2023-11-30 00:08:39 +08:00
Flexible(
fit: FlexFit.tight,
child: Container(
padding: REdgeInsets.only(
left: 45.0,
top: 10.0,
right: 45.0,
),
child: buildMsgList(context),
2023-11-28 10:44:58 +08:00
),
),
2023-11-30 00:08:39 +08:00
HookBuilder(builder: (context) {
2023-11-28 20:25:09 +08:00
useMemoized(() async {
2023-11-30 00:08:39 +08:00
for (int i = 0;
i < controller.chatInputMsg.value.length + 1;
i++) {
controller.textController.text =
controller.chatInputMsg.value.substring(0, i);
await Future.delayed(const Duration(milliseconds: 80));
2023-11-28 20:25:09 +08:00
}
});
return ChatInputWidget(
2023-11-30 00:08:39 +08:00
controller: controller.textController,
2023-11-28 20:25:09 +08:00
onPressed: (txt) {
controller.addSendMsg(txt);
},
);
2023-11-30 00:08:39 +08:00
}),
],
),
2023-11-28 10:44:58 +08:00
);
}
Widget buildMsgList(BuildContext context) {
return Obx(
() => ListView.builder(
shrinkWrap: true,
itemCount: controller.chatMsgList.length,
controller: controller.scrollController,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (_, int index) {
ChatMsg chat = controller.chatMsgList[index];
if (chat.isBot == 1) {
return ReceiveMessageWidget(
'AI小助手',
Images.avatar,
child: Text(
chat.text!,
style: TextStyles.mediumGray3315,
),
);
} else {
return SendMessageWidget(
chat.text!,
controller.account,
Images.avatarUser,
);
}
},
),
);
}
}