import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../../../data/services/network/api.dart'; class TemplateEditView extends StatefulWidget { const TemplateEditView({super.key}); @override State createState() => _TemplateEditViewState(); } class _TemplateEditViewState extends State { final TextEditingController _nameController = TextEditingController(); final TextEditingController _descController = TextEditingController(); final TextEditingController _promptController = TextEditingController(); bool _isEnable = false; @override void initState() { super.initState(); } @override void dispose() { _nameController.dispose(); _descController.dispose(); _promptController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final isDarkMode = Theme.of(context).brightness == Brightness.dark; return GestureDetector( onTap: () => FocusScope.of(context).unfocus(), child: Scaffold( backgroundColor: isDarkMode ? Colors.black : Colors.grey[50], appBar: _buildAppBar(isDarkMode), body: _buildBody(isDarkMode), ), ); } // 构建应用栏 PreferredSizeWidget _buildAppBar(bool isDarkMode) { return AppBar( backgroundColor: isDarkMode ? Colors.black : Colors.white, elevation: 0.5, leading: IconButton( icon: Icon( Icons.arrow_back_ios, color: isDarkMode ? Colors.white : Colors.black, size: 20.sp, ), onPressed: () => Get.back(), ), title: Text( '创建模版', style: TextStyle( fontSize: 17.sp, fontWeight: FontWeight.w600, color: isDarkMode ? Colors.white : Colors.black, ), ), centerTitle: true, ); } // 构建主体内容 Widget _buildBody(bool isDarkMode) { return Column( children: [ Expanded( child: ListView( padding: EdgeInsets.symmetric(horizontal: 12.w), children: [ _input(isDarkMode, '名称', _nameController), _input(isDarkMode, '描述', _descController), _input( isDarkMode, '模版', _promptController, minLines: 8, maxLines: 100, hintText: '请输入模版内容!温馨提示:点击上方AI,根据上面填写的名称和描述,可以帮助你快速生成模版内容', ), ], ), ), Padding( padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 20.w), child: GestureDetector( onTap: () { if (_nameController.text.isNotEmpty && _descController.text.isNotEmpty && _promptController.text.isNotEmpty) { _submit(); } }, child: Container( height: 48.w, alignment: Alignment.center, decoration: BoxDecoration( color: _nameController.text.isNotEmpty && _descController.text.isNotEmpty && _promptController.text.isNotEmpty ? Colors.black : Colors.grey, borderRadius: BorderRadius.circular(12.r), ), child: Text( '提交', style: TextStyle( fontSize: 16.sp, color: Colors.white, ), ), ), ), ), ], ); } Widget _input( bool isDarkMode, String title, TextEditingController controller, { int minLines = 1, int maxLines = 1, String? hintText, }) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.only(left: 10.w), child: Text( title, style: TextStyle( fontSize: 14.sp, color: isDarkMode ? Colors.white60 : Colors.black87, ), ), ), Container( margin: EdgeInsets.only(top: 10.w, bottom: 20.w), alignment: Alignment.center, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12.w), boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.05), blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: TextField( controller: controller, minLines: minLines, maxLines: maxLines, style: TextStyle( color: Colors.black87, fontSize: 14.sp, ), decoration: InputDecoration( hintText: hintText ?? '请输入$title', hintStyle: TextStyle( color: Colors.black54, fontSize: 14.sp, ), isDense: true, fillColor: Colors.transparent, border: InputBorder.none, contentPadding: EdgeInsets.all(10.w), ), onChanged: (value) { bool isEnable = false; if (_nameController.text.isNotEmpty && _descController.text.isNotEmpty && _promptController.text.isNotEmpty) { isEnable = true; } if (_isEnable != isEnable) { setState(() { _isEnable = isEnable; }); } }, ), ), ], ); } void _submit() async { EasyLoading.show(); Map data = { "template": { 'ttype': '自定义', 'tags': '', 'icon': 'auto_fix_high', 'outline': '您将扮演一名会议事件归纳专家,能准确抓住会议中事件的关键点,并每个事件只需一句话精简总结。', 'title': _nameController.text, 'description': _descController.text, 'template': _promptController.text, }, }; var response = await Api.addEchomeetTemplates(data); if (response != null) {} EasyLoading.dismiss(); } }