feat:增加图表组件

This commit is contained in:
2025-07-13 22:00:55 +08:00
parent 55ca36cba2
commit 8a1b507166
14 changed files with 464 additions and 218 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:food_hub_app/utils/index.dart';
import 'package:food_hub_app/widgets/common/index.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
@@ -28,29 +29,7 @@ class _RecordFormPage extends State<RecordFormPage> {
XFile? _selectedImage;
/// 整个表单存放的数据
Map<String, dynamic> _formData = {
"name": '',
"date": '',
"gender": '',
"birth": '',
"place": '',
"age": "2",
"description": "2",
"resume": '',
"photo": '',
};
Map<String, dynamic> _formItemNotifier = {
"name": '',
"password": '',
"gender": '',
"birth": '',
"place": '',
"age": '2',
"description": '',
"resume": '',
"photo": "",
};
Map<String, dynamic> _formData = {"name": '', "date": '', "photo": ''};
/// 定义整个校验规则
final Map<String, TDFormValidation> _validationRules = {
@@ -71,14 +50,6 @@ class _RecordFormPage extends State<RecordFormPage> {
),
};
void confirmClick(BuildContext context) {
if (_formKey.currentState?.saveAndValidate() ?? false) {
// showSuccessToast("新增记录成功");
} else {
// showErrorToast("请先提交信息");
}
}
List<TDUploadFile> files = [];
List<TDUploadFile> _onValueChanged(
@@ -108,28 +79,28 @@ class _RecordFormPage extends State<RecordFormPage> {
@override
void initState() {
/// 三个文本型的表格单元
for (var i = 0; i < 4; i++) {
_controller.add(TextEditingController());
}
_formData.forEach((key, value) {
_formItemNotifier[key] = FormItemNotifier();
});
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
}
String parseDatePickerSelected(Map<String, int> selected) {
final String year = selected['year'].toString().padLeft(4, '0');
final String month = selected['month'].toString().padLeft(2, '0');
final String day = selected['day'].toString().padLeft(2, '0');
return '$year-$month-$day';
void _confirmClick(BuildContext context) {
if (_formKey.currentState?.saveAndValidate() ?? false) {
// showSuccessToast("新增记录成功");
print(_formData);
} else {
TDMessage.showMessage(
context: context,
visible: true,
icon: true,
content: "请先输入信息",
theme: MessageTheme.error,
duration: 3000,
);
}
}
TDFormItem buildNameItem() {
@@ -150,8 +121,8 @@ class _RecordFormPage extends State<RecordFormPage> {
backgroundColor: Colors.white,
additionInfoColor: TDTheme.of(context).errorColor6,
showBottomDivider: false,
onChanged: (val) {
_formData['name'] = val;
onChanged: (value) {
_formData['name'] = value;
},
),
);
@@ -168,21 +139,19 @@ class _RecordFormPage extends State<RecordFormPage> {
hintText: '请选择完成时间',
select: _formData['date'],
selectFn: (BuildContext context) {
DateTime now = DateTime.now();
TDPicker.showDatePicker(
context,
title: '选择时间',
onConfirm: (selected) {
setState(() {
print(selected);
_selected_1 =
'${selected['year'].toString().padLeft(4, '0')}-${selected['month'].toString().padLeft(2, '0')}-${selected['day'].toString().padLeft(2, '0')}';
_formItemNotifier['birth']?.upDataForm(_selected_1);
_formData['date'] = parseDatePickerSelected(selected);
});
Navigator.of(context).pop();
},
dateStart: [1999, 01, 01],
dateEnd: [2050, 12, 31],
initialDate: [2012, 1, 1],
dateStart: [2000, 01, 01],
dateEnd: [2100, 12, 31],
initialDate: [now.year, now.month, now.day],
);
},
);
@@ -194,7 +163,6 @@ class _RecordFormPage extends State<RecordFormPage> {
name: 'photo',
labelWidth: 82.0,
type: TDFormItemType.upLoadImg,
formItemNotifier: _formItemNotifier['photo'],
child: TDUpload(
files: files,
onError: print,
@@ -202,9 +170,7 @@ class _RecordFormPage extends State<RecordFormPage> {
onChange: ((imgList, type) {
files = _onValueChanged(files ?? [], imgList, type);
List imgs = files.map((e) => e.remotePath ?? e.assetPath).toList();
setState(() {
_formItemNotifier['photo'].upDataForm(imgs.join(','));
});
setState(() {});
}),
),
);
@@ -214,21 +180,16 @@ class _RecordFormPage extends State<RecordFormPage> {
return Container(
decoration: BoxDecoration(color: TDTheme.of(context).whiteColor1),
child: Padding(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: TDButton(
text: '重置',
text: '取消',
type: TDButtonType.fill,
theme: TDButtonTheme.light,
shape: TDButtonShape.rectangle,
onTap: () {
//用户名称
_controller[0].clear();
//密码
_controller[1].clear();
},
onTap: () => Navigator.pop(context),
),
),
SizedBox(width: 20),
@@ -238,7 +199,7 @@ class _RecordFormPage extends State<RecordFormPage> {
type: TDButtonType.fill,
theme: TDButtonTheme.primary,
shape: TDButtonShape.rectangle,
onTap: () => {},
onTap: () => _confirmClick(context),
),
),
],
@@ -250,7 +211,14 @@ class _RecordFormPage extends State<RecordFormPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('新增记录'), backgroundColor: Colors.white),
appBar: AppBar(
title: Text('新增记录', style: TextStyle(color: Colors.white)),
backgroundColor: Theme.of(context).primaryColor,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context)
),
),
backgroundColor: Color(0xFFF5F5F5),
body: Padding(
padding: const EdgeInsets.all(10),