You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
9.4 KiB

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../data/services/db/sqflite_api.dart';
import '../../../../data/services/network/api.dart';
import '../../controllers/meeting_details_controller.dart';
import 'template_edit_view.dart';
class TemplateDetailsView extends StatefulWidget {
final Map data;
final bool isEdit;
const TemplateDetailsView(this.data, {super.key, this.isEdit = false});
@override
State<TemplateDetailsView> createState() => _TemplateDetailsViewState();
}
class _TemplateDetailsViewState extends State<TemplateDetailsView> {
final _controller = Get.find<MeetingDetailsController>();
Map _templateData = {};
@override
void initState() {
super.initState();
_templateData = widget.data;
}
@override
Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return 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: [
Padding(
padding: EdgeInsets.only(top: 20.w),
child: Text(
_templateData['name'],
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: EdgeInsets.only(top: 20.w, bottom: 5.w),
child: Text(
'标签',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
),
),
),
Wrap(
spacing: 5.w,
children: List.generate(
_templateData['tag'].length,
(int idx) {
return Container(
padding:
EdgeInsets.symmetric(horizontal: 5.w, vertical: 2.w),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(4.r),
),
child: Text(
_templateData['tag'][idx],
style: TextStyle(
fontSize: 10.sp,
color: Colors.grey[600],
),
),
);
},
),
),
Padding(
padding: EdgeInsets.only(top: 20.w, bottom: 5.w),
child: Text(
'描述',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
),
),
),
Text(
_templateData['desc'],
style: TextStyle(
fontSize: 14.sp,
color: Colors.grey[600],
),
),
Padding(
padding: EdgeInsets.only(top: 20.w, bottom: 5.w),
child: Text(
'模版',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
),
),
),
MarkdownBody(
data: _templateData['prompt'],
),
],
),
),
if (widget.isEdit)
Padding(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 20.w),
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () async {
var result = await Get.to(
() => TemplateEditView(data: _templateData));
if (result != null) {
setState(() {
_templateData['name'] = result['name'];
_templateData['desc'] = result['desc'];
_templateData['prompt'] = result['prompt'];
});
}
},
child: Container(
height: 48.w,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color: Colors.black,
),
),
child: Text(
'修改',
style: TextStyle(
fontSize: 16.sp,
color: Colors.black,
),
),
),
),
),
15.horizontalSpace,
Expanded(
child: GestureDetector(
onTap: () {
Get.dialog(
AlertDialog(
backgroundColor:
isDarkMode ? Colors.grey[900] : Colors.white,
title: Text(
'删除模版',
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black87,
),
),
content: Text(
'确定要删除当前模版吗?',
style: TextStyle(
color: isDarkMode
? Colors.grey[400]
: Colors.grey[600],
),
),
actions: [
TextButton(
onPressed: () => Get.back(),
child: Text(
'cancel'.tr,
style: TextStyle(
color: isDarkMode
? Colors.grey[400]
: Colors.grey[600],
),
),
),
TextButton(
onPressed: () async {
Get.back();
var response = await Api.delEchomeetTemplates({
'ids': [_templateData['id']],
});
if (response != null) {
await SqfliteApi.deleteMeetingTemplate(
_templateData['id']);
_controller.categoryTemplateList =
await SqfliteApi
.getMeetingCategoryTemplateList();
_controller.deleteTemplateId =
_templateData['id'];
Get.back();
}
},
child: Text(
'confirm'.tr,
style: const TextStyle(
color: Colors.red,
),
),
),
],
),
);
},
child: Container(
height: 48.w,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(12.r),
),
child: Text(
'删除',
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
),
),
),
),
),
],
),
),
],
);
}
}