import 'package:dreampad/app/modules/home/models/chat_msg_model.dart'; import 'package:dreampad/app/shared/shared.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; 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 { 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) { 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(); }, ), Center( child: Text( controller.selectKnowledge.value!.title!, style: TextStyles.boldWhiteShadow34_200, ), ) ], ), ), const RSizedBox(height: 10.0), Row( 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, ), ), 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, ), ], ), ) ], ), Flexible( fit: FlexFit.tight, child: Container( padding: REdgeInsets.only( left: 45.0, top: 10.0, right: 45.0, ), child: buildMsgList(context), ), ), HookBuilder(builder: (context) { useMemoized(() async { 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)); } }, [controller.chatInputMsg.value]); return ChatInputWidget( controller: controller.textController, onPressed: (txt) { controller.addSendMsg(txt); }, ); }), ], ), ); } 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, ); } }, ), ); } }