feat:更新颜色模块
This commit is contained in:
@@ -123,7 +123,7 @@ class StatsPageState extends State<StatsPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
buildFlispStatsCard(allFlisps),
|
buildFlispStatsCard(context, allFlisps),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ class StatsPageState extends State<StatsPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Expanded(child: buildTodoStatsCard(allTodos)),
|
Expanded(child: buildTodoStatsCard(context, allTodos)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class TodoPageState extends State<TodoPage> {
|
|||||||
children: [
|
children: [
|
||||||
_buildTodoTabs(),
|
_buildTodoTabs(),
|
||||||
_buildTodoSegment(),
|
_buildTodoSegment(),
|
||||||
|
SizedBox(height: 6),
|
||||||
Expanded(child: _buildActiveTodoList(context)),
|
Expanded(child: _buildActiveTodoList(context)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,268 +24,275 @@ class CalendarForm extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CalendarFormState extends State<CalendarForm> {
|
class _CalendarFormState extends State<CalendarForm> {
|
||||||
|
final int maxTitleCount = 10;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget buildTitle() {
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final int maxTitleCount = 10;
|
|
||||||
final provider = Provider.of<CalendarProvider>(context);
|
|
||||||
final colors = Theme.of(context).colorScheme;
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
Widget buildTitle() {
|
return Row(
|
||||||
return Row(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
||||||
children: [
|
Icon(
|
||||||
Icon(
|
widget.isEditing ? Icons.edit_note : Icons.add_task,
|
||||||
widget.isEditing ? Icons.edit_note : Icons.add_task,
|
color: colors.primary,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
widget.isEditing ? '编辑日程事项' : '添加日程事项',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
color: colors.primary,
|
color: colors.primary,
|
||||||
size: 24,
|
|
||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
),
|
||||||
Text(
|
],
|
||||||
widget.isEditing ? '编辑日程事项' : '添加日程事项',
|
);
|
||||||
style: TextStyle(
|
}
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: colors.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String? titleFieldValidator(value) {
|
String? titleFieldValidator(value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return '请输入标题';
|
return '请输入标题';
|
||||||
}
|
|
||||||
if (value.length > maxTitleCount) {
|
|
||||||
return '标题不能超过$maxTitleCount个字符';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
if (value.length > maxTitleCount) {
|
||||||
|
return '标题不能超过$maxTitleCount个字符';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
FormBuilderTextField buildTitleField() {
|
FormBuilderTextField buildTitleField(CalendarProvider provider) {
|
||||||
return FormBuilderTextField(
|
final colors = Theme.of(context).colorScheme;
|
||||||
name: 'title',
|
|
||||||
initialValue: provider.formItem.title,
|
return FormBuilderTextField(
|
||||||
onChanged: (value) {
|
name: 'title',
|
||||||
setState(() {
|
initialValue: provider.formItem.title,
|
||||||
provider.formItem.title = value ?? '';
|
onChanged: (value) {
|
||||||
});
|
setState(() {
|
||||||
},
|
provider.formItem.title = value ?? '';
|
||||||
decoration: InputDecoration(
|
});
|
||||||
label: RichText(
|
},
|
||||||
text: TextSpan(
|
decoration: InputDecoration(
|
||||||
text: '内容',
|
label: RichText(
|
||||||
style: TextStyle(color: Colors.grey.shade700, fontSize: 16),
|
text: TextSpan(
|
||||||
children: const [
|
text: '内容',
|
||||||
TextSpan(
|
style: TextStyle(color: Colors.grey.shade700, fontSize: 16),
|
||||||
text: '*',
|
children: const [
|
||||||
style: TextStyle(
|
TextSpan(
|
||||||
color: Colors.red,
|
text: '*',
|
||||||
fontSize: 18,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.red,
|
||||||
),
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
hintText: '请输入日程标题...',
|
|
||||||
hintStyle: TextStyle(color: Colors.grey),
|
|
||||||
counterText: '',
|
|
||||||
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
|
||||||
border: buildFormBoard(),
|
|
||||||
enabledBorder: buildFormEnabledBoard(),
|
|
||||||
focusedBorder: buildFormFocusedBoard(colors),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
prefixIcon: Icon(Icons.title, color: Colors.blue),
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
),
|
||||||
maxLength: maxTitleCount,
|
hintText: '请输入日程标题...',
|
||||||
validator: (value) => titleFieldValidator(value),
|
hintStyle: TextStyle(color: Colors.grey),
|
||||||
);
|
counterText: '',
|
||||||
|
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
||||||
|
border: buildFormBoard(),
|
||||||
|
enabledBorder: buildFormEnabledBoard(),
|
||||||
|
focusedBorder: buildFormFocusedBoard(colors),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
prefixIcon: Icon(Icons.title, color: Colors.blue),
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
maxLength: maxTitleCount,
|
||||||
|
validator: (value) => titleFieldValidator(value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String? startTimeFieldValidator(CalendarProvider provider, value) {
|
||||||
|
if (value == null) {
|
||||||
|
return '请选择开始时间';
|
||||||
|
}
|
||||||
|
if (value.isBefore(DateTime.now())) {
|
||||||
|
return '不能选择过去的日期';
|
||||||
}
|
}
|
||||||
|
|
||||||
String? startTimeFieldValidator(value) {
|
final endTime = provider.formItem.endTime;
|
||||||
if (value == null) {
|
if (endTime != null && endTime.isBefore(value)) {
|
||||||
return '请选择开始时间';
|
return '结束时间不能早于开始时间';
|
||||||
}
|
}
|
||||||
if (value.isBefore(DateTime.now())) {
|
if (endTime != null && endTime.isAtSameMomentAs(value)) {
|
||||||
return '不能选择过去的日期';
|
return '开始时间不能等于结束时间';
|
||||||
}
|
|
||||||
|
|
||||||
final endTime = provider.formItem.endTime;
|
|
||||||
if (endTime != null && endTime.isBefore(value)) {
|
|
||||||
return '结束时间不能早于开始时间';
|
|
||||||
}
|
|
||||||
if (endTime != null && endTime.isAtSameMomentAs(value)) {
|
|
||||||
return '开始时间不能等于结束时间';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormBuilderDateTimePicker buildStartTimeField() {
|
return null;
|
||||||
var startTime = provider.formItem.startTime;
|
}
|
||||||
|
|
||||||
return FormBuilderDateTimePicker(
|
FormBuilderDateTimePicker buildStartTimeField(CalendarProvider provider) {
|
||||||
name: 'startTime',
|
final colors = Theme.of(context).colorScheme;
|
||||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
var startTime = provider.formItem.startTime;
|
||||||
initialValue: startTime,
|
|
||||||
inputType: InputType.both,
|
return FormBuilderDateTimePicker(
|
||||||
onChanged: (value) {
|
name: 'startTime',
|
||||||
setState(() {
|
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||||
provider.formItem.startTime = value!;
|
initialValue: startTime,
|
||||||
});
|
inputType: InputType.both,
|
||||||
},
|
onChanged: (value) {
|
||||||
decoration: InputDecoration(
|
setState(() {
|
||||||
labelText:
|
provider.formItem.startTime = value!;
|
||||||
startTime == null ? '选择开始时间' : '开始时间: ${formatTime(startTime)}',
|
});
|
||||||
labelStyle: TextStyle(
|
},
|
||||||
color: startTime == null ? Colors.grey : Colors.black87,
|
decoration: InputDecoration(
|
||||||
),
|
labelText:
|
||||||
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
startTime == null ? '选择开始时间' : '开始时间: ${formatTime(startTime)}',
|
||||||
border: buildFormBoard(),
|
labelStyle: TextStyle(
|
||||||
enabledBorder: buildFormEnabledBoard(),
|
color: startTime == null ? Colors.grey : Colors.black87,
|
||||||
focusedBorder: buildFormFocusedBoard(colors),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
),
|
||||||
validator: (value) => startTimeFieldValidator(value),
|
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
||||||
);
|
border: buildFormBoard(),
|
||||||
|
enabledBorder: buildFormEnabledBoard(),
|
||||||
|
focusedBorder: buildFormFocusedBoard(colors),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
validator: (value) => startTimeFieldValidator(provider, value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String? endTimeFieldValidator(CalendarProvider provider, value) {
|
||||||
|
if (value == null) {
|
||||||
|
return '请选择结束时间';
|
||||||
|
}
|
||||||
|
if (value.isBefore(DateTime.now())) {
|
||||||
|
return '不能选择过去的日期';
|
||||||
}
|
}
|
||||||
|
|
||||||
String? endTimeFieldValidator(value) {
|
final startTime = provider.formItem.startTime;
|
||||||
if (value == null) {
|
if (startTime != null && value.isBefore(startTime)) {
|
||||||
return '请选择结束时间';
|
return '结束时间不能早于开始时间';
|
||||||
}
|
}
|
||||||
if (value.isBefore(DateTime.now())) {
|
if (startTime != null && startTime.isAtSameMomentAs(value)) {
|
||||||
return '不能选择过去的日期';
|
return '开始时间不能等于结束时间';
|
||||||
}
|
|
||||||
|
|
||||||
final startTime = provider.formItem.startTime;
|
|
||||||
if (startTime != null && value.isBefore(startTime)) {
|
|
||||||
return '结束时间不能早于开始时间';
|
|
||||||
}
|
|
||||||
if (startTime != null && startTime.isAtSameMomentAs(value)) {
|
|
||||||
return '开始时间不能等于结束时间';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormBuilderDateTimePicker buildEndTimeField() {
|
return null;
|
||||||
var endTime = provider.formItem.endTime;
|
}
|
||||||
|
|
||||||
return FormBuilderDateTimePicker(
|
FormBuilderDateTimePicker buildEndTimeField(CalendarProvider provider) {
|
||||||
name: 'endTime',
|
final colors = Theme.of(context).colorScheme;
|
||||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
var endTime = provider.formItem.endTime;
|
||||||
initialValue: endTime,
|
|
||||||
inputType: InputType.both,
|
return FormBuilderDateTimePicker(
|
||||||
onChanged: (value) {
|
name: 'endTime',
|
||||||
setState(() {
|
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||||
provider.formItem.endTime = value!;
|
initialValue: endTime,
|
||||||
});
|
inputType: InputType.both,
|
||||||
},
|
onChanged: (value) {
|
||||||
decoration: InputDecoration(
|
setState(() {
|
||||||
labelText:
|
provider.formItem.endTime = value!;
|
||||||
endTime == null ? '选择结束时间' : '结束时间: ${formatTime(endTime)}',
|
});
|
||||||
labelStyle: TextStyle(
|
},
|
||||||
color: endTime == null ? Colors.grey : Colors.black87,
|
decoration: InputDecoration(
|
||||||
),
|
labelText: endTime == null ? '选择结束时间' : '结束时间: ${formatTime(endTime)}',
|
||||||
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
labelStyle: TextStyle(
|
||||||
border: buildFormBoard(),
|
color: endTime == null ? Colors.grey : Colors.black87,
|
||||||
enabledBorder: buildFormEnabledBoard(),
|
|
||||||
focusedBorder: buildFormFocusedBoard(colors),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
),
|
||||||
validator: (value) => endTimeFieldValidator(value),
|
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
||||||
);
|
border: buildFormBoard(),
|
||||||
|
enabledBorder: buildFormEnabledBoard(),
|
||||||
|
focusedBorder: buildFormFocusedBoard(colors),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
validator: (value) => endTimeFieldValidator(provider, value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton buildClearScheduled(CalendarProvider provider) {
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(Icons.clear, size: 18),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.scheduledTime = null;
|
||||||
|
});
|
||||||
|
widget.formKey.currentState?.fields['scheduledTime']?.didChange(null);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String? scheduledTimeFieldValidator(value) {
|
||||||
|
if (value != null && value.isBefore(DateTime.now())) {
|
||||||
|
return '不能选择过去的日期';
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
IconButton buildClearScheduled() {
|
FormBuilderDateTimePicker buildScheduledTimeField(CalendarProvider provider) {
|
||||||
return IconButton(
|
final colors = Theme.of(context).colorScheme;
|
||||||
icon: Icon(Icons.clear, size: 18),
|
var scheduledTime = provider.formItem.scheduledTime;
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.scheduledTime = null;
|
|
||||||
});
|
|
||||||
widget.formKey.currentState?.fields['scheduledTime']?.didChange(null);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String? scheduledTimeFieldValidator(value) {
|
return FormBuilderDateTimePicker(
|
||||||
if (value != null && value.isBefore(DateTime.now())) {
|
name: 'scheduledTime',
|
||||||
return '不能选择过去的日期';
|
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||||
}
|
initialValue: scheduledTime,
|
||||||
return null;
|
inputType: InputType.both,
|
||||||
}
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
FormBuilderDateTimePicker buildScheduledTimeField() {
|
provider.formItem.scheduledTime = value;
|
||||||
var scheduledTime = provider.formItem.scheduledTime;
|
});
|
||||||
|
},
|
||||||
return FormBuilderDateTimePicker(
|
decoration: InputDecoration(
|
||||||
name: 'scheduledTime',
|
labelText:
|
||||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
scheduledTime == null
|
||||||
initialValue: scheduledTime,
|
? '选择提醒日期'
|
||||||
inputType: InputType.both,
|
: '提醒: ${formatTime(scheduledTime)}',
|
||||||
onChanged: (value) {
|
labelStyle: TextStyle(
|
||||||
setState(() {
|
color: scheduledTime == null ? Colors.grey : Colors.black87,
|
||||||
provider.formItem.scheduledTime = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText:
|
|
||||||
scheduledTime == null
|
|
||||||
? '选择提醒日期'
|
|
||||||
: '提醒: ${formatTime(scheduledTime)}',
|
|
||||||
labelStyle: TextStyle(
|
|
||||||
color: scheduledTime == null ? Colors.grey : Colors.black87,
|
|
||||||
),
|
|
||||||
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
|
||||||
border: buildFormBoard(),
|
|
||||||
enabledBorder: buildFormEnabledBoard(),
|
|
||||||
focusedBorder: buildFormFocusedBoard(colors),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
suffixIcon: scheduledTime != null ? buildClearScheduled() : null,
|
|
||||||
),
|
),
|
||||||
validator: (value) => scheduledTimeFieldValidator(value),
|
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
||||||
);
|
border: buildFormBoard(),
|
||||||
}
|
enabledBorder: buildFormEnabledBoard(),
|
||||||
|
focusedBorder: buildFormFocusedBoard(colors),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
suffixIcon:
|
||||||
|
scheduledTime != null ? buildClearScheduled(provider) : null,
|
||||||
|
),
|
||||||
|
validator: (value) => scheduledTimeFieldValidator(value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
FormBuilder buildForm() {
|
FormBuilder buildForm(CalendarProvider provider) {
|
||||||
return FormBuilder(
|
return FormBuilder(
|
||||||
key: widget.formKey,
|
key: widget.formKey,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
buildTitleField(),
|
buildTitleField(provider),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
buildStartTimeField(),
|
buildStartTimeField(provider),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
buildEndTimeField(),
|
buildEndTimeField(provider),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
buildScheduledTimeField(),
|
buildScheduledTimeField(provider),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final provider = Provider.of<CalendarProvider>(context);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [buildTitle(), SizedBox(height: 20), buildForm()],
|
children: [buildTitle(), SizedBox(height: 20), buildForm(provider)],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,16 +193,18 @@ Widget buildToggleSwitch<T extends Enum>({
|
|||||||
required List<String> labels,
|
required List<String> labels,
|
||||||
required ValueChanged<T> onTabChanged,
|
required ValueChanged<T> onTabChanged,
|
||||||
}) {
|
}) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
return ToggleSwitch(
|
return ToggleSwitch(
|
||||||
minWidth: 90.0,
|
minWidth: 90.0,
|
||||||
minHeight: 40.0,
|
minHeight: 40.0,
|
||||||
initialLabelIndex: tabValues.indexOf(currentTab),
|
initialLabelIndex: tabValues.indexOf(currentTab),
|
||||||
totalSwitches: tabValues.length,
|
totalSwitches: tabValues.length,
|
||||||
labels: labels,
|
labels: labels,
|
||||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
activeBgColor: [colors.primary],
|
||||||
activeFgColor: Colors.white,
|
activeFgColor: Colors.white,
|
||||||
inactiveBgColor: Colors.grey.shade200,
|
inactiveBgColor: colors.surfaceContainer,
|
||||||
inactiveFgColor: Colors.grey.shade700,
|
inactiveFgColor: colors.onSurface,
|
||||||
cornerRadius: 12.0,
|
cornerRadius: 12.0,
|
||||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||||
onToggle: (index) {
|
onToggle: (index) {
|
||||||
@@ -216,7 +218,7 @@ Widget buildToggleSwitch<T extends Enum>({
|
|||||||
ButtonStyle buildSegmentStyle(ColorScheme colors) {
|
ButtonStyle buildSegmentStyle(ColorScheme colors) {
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
side: WidgetStateProperty.all<BorderSide>(
|
side: WidgetStateProperty.all<BorderSide>(
|
||||||
const BorderSide(color: Colors.transparent, width: 0),
|
BorderSide(color: colors.surface, width: 0),
|
||||||
),
|
),
|
||||||
iconColor: WidgetStateProperty.resolveWith<Color>(
|
iconColor: WidgetStateProperty.resolveWith<Color>(
|
||||||
(Set<WidgetState> states) {
|
(Set<WidgetState> states) {
|
||||||
@@ -232,7 +234,7 @@ ButtonStyle buildSegmentStyle(ColorScheme colors) {
|
|||||||
if (states.contains(WidgetState.selected)) {
|
if (states.contains(WidgetState.selected)) {
|
||||||
return colors.primary;
|
return colors.primary;
|
||||||
}
|
}
|
||||||
return Colors.grey.shade200;
|
return colors.surfaceContainer;
|
||||||
}),
|
}),
|
||||||
foregroundColor: WidgetStateProperty.resolveWith<Color>((
|
foregroundColor: WidgetStateProperty.resolveWith<Color>((
|
||||||
Set<WidgetState> states,
|
Set<WidgetState> states,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class FlispForm extends StatefulWidget {
|
|||||||
|
|
||||||
class _FlispFormState extends State<FlispForm> {
|
class _FlispFormState extends State<FlispForm> {
|
||||||
bool _showTagOptions = false;
|
bool _showTagOptions = false;
|
||||||
|
final int maxContentCount = 100;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -62,223 +63,211 @@ class _FlispFormState extends State<FlispForm> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget buildContentField(FlispProvider provider) {
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final int maxContentCount = 100;
|
|
||||||
final provider = Provider.of<FlispProvider>(context);
|
|
||||||
final colors = Theme.of(context).colorScheme;
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
Widget buildContentField() {
|
return FormBuilderTextField(
|
||||||
return FormBuilderTextField(
|
name: 'content',
|
||||||
name: 'content',
|
initialValue: provider.formItem.content,
|
||||||
initialValue: provider.formItem.content,
|
onChanged: (value) {
|
||||||
onChanged: (value) {
|
setState(() {
|
||||||
setState(() {
|
provider.formItem.content = value ?? '';
|
||||||
provider.formItem.content = value ?? '';
|
});
|
||||||
});
|
},
|
||||||
},
|
decoration: InputDecoration(
|
||||||
decoration: InputDecoration(
|
hintText: '记录你的灵感瞬间...',
|
||||||
hintText: '记录你的灵感瞬间...',
|
hintStyle: TextStyle(color: Colors.grey),
|
||||||
hintStyle: TextStyle(color: Colors.grey),
|
counterText: '',
|
||||||
counterText: '',
|
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
border: OutlineInputBorder(
|
||||||
border: OutlineInputBorder(
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: colors.primary),
|
|
||||||
),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
),
|
||||||
minLines: 4,
|
enabledBorder: OutlineInputBorder(
|
||||||
maxLines: 8,
|
borderRadius: BorderRadius.circular(12),
|
||||||
maxLength: maxContentCount,
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
validator: (value) {
|
|
||||||
if (value != null && value.isEmpty) {
|
|
||||||
return '请输入内容';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value != null && value.length > maxContentCount) {
|
|
||||||
return '内容不能超过$maxContentCount个字符';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildFormBody() {
|
|
||||||
return Expanded(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
buildContentField(),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
buildFlispTag(provider.formItem),
|
|
||||||
SizedBox(height: 12),
|
|
||||||
if (provider.formItem.imageUrl.isNotEmpty)
|
|
||||||
buildFlispImage(
|
|
||||||
flisp: provider.formItem,
|
|
||||||
showDelete: true,
|
|
||||||
onDelete: _deleteImage,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
focusedBorder: OutlineInputBorder(
|
||||||
}
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
void selectImage() async {
|
|
||||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
|
||||||
type: FileType.custom,
|
|
||||||
allowedExtensions: ['jpg', 'jpeg', 'png'],
|
|
||||||
allowMultiple: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
PlatformFile file = result.files.first;
|
|
||||||
final fileName = await MinIOHelper().uploadFile(file: file);
|
|
||||||
_selectImage(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildSelectImageButton() {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => selectImage(),
|
|
||||||
child: Container(
|
|
||||||
width: 36,
|
|
||||||
height: 36,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.blue.withAlpha(50),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: Colors.blue.withAlpha(80), width: 1),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
Icons.photo_library_rounded,
|
|
||||||
size: 20,
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
filled: true,
|
||||||
}
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
minLines: 4,
|
||||||
|
maxLines: 8,
|
||||||
|
maxLength: maxContentCount,
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null && value.isEmpty) {
|
||||||
|
return '请输入内容';
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildSelectTagButton() {
|
if (value != null && value.length > maxContentCount) {
|
||||||
return GestureDetector(
|
return '内容不能超过$maxContentCount个字符';
|
||||||
onTap: _toggleTagOptions,
|
}
|
||||||
child: Container(
|
return null;
|
||||||
width: 36,
|
},
|
||||||
height: 36,
|
);
|
||||||
decoration: BoxDecoration(
|
}
|
||||||
color: Colors.orange.withAlpha(50),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: Colors.orange.withAlpha(80), width: 1),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
Icons.local_offer_rounded,
|
|
||||||
size: 20,
|
|
||||||
color: Colors.orange,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildConfirmButton() {
|
Widget buildFormBody(FlispProvider provider) {
|
||||||
return Container(
|
return Expanded(
|
||||||
width: 48,
|
child: SingleChildScrollView(
|
||||||
height: 48,
|
child: Column(
|
||||||
decoration: BoxDecoration(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
color: colors.primary,
|
|
||||||
borderRadius: BorderRadius.circular(24),
|
|
||||||
),
|
|
||||||
child: IconButton(
|
|
||||||
icon: Icon(Icons.arrow_forward_rounded, size: 24),
|
|
||||||
color: Colors.white,
|
|
||||||
onPressed: () => widget.onOk(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildShowTagOptions() {
|
|
||||||
// 计算弹窗位置(基于标签按钮位置)
|
|
||||||
return Positioned(
|
|
||||||
bottom: 50, // 调整垂直位置
|
|
||||||
left: 60, // 调整水平位置
|
|
||||||
child: Container(
|
|
||||||
width: 90,
|
|
||||||
padding: EdgeInsets.all(8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black26,
|
|
||||||
blurRadius: 8,
|
|
||||||
offset: Offset(0, 2),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children:
|
|
||||||
FlispTag.values.map((tag) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => _selectTag(tag),
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: tag.color,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
tag.icon,
|
|
||||||
size: 12,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(tag.label, style: TextStyle(fontSize: 12)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildBottomButton() {
|
|
||||||
return Container(
|
|
||||||
padding: EdgeInsets.only(top: 16),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
buildContentField(provider),
|
||||||
children: [
|
SizedBox(height: 8),
|
||||||
buildSelectImageButton(),
|
buildFlispTag(context, provider.formItem),
|
||||||
SizedBox(width: 12),
|
SizedBox(height: 12),
|
||||||
buildSelectTagButton(),
|
if (provider.formItem.imageUrl.isNotEmpty)
|
||||||
],
|
buildFlispImage(
|
||||||
),
|
flisp: provider.formItem,
|
||||||
buildConfirmButton(),
|
showDelete: true,
|
||||||
|
onDelete: _deleteImage,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void selectImage() async {
|
||||||
|
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ['jpg', 'jpeg', 'png'],
|
||||||
|
allowMultiple: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
PlatformFile file = result.files.first;
|
||||||
|
final fileName = await MinIOHelper().uploadFile(file: file);
|
||||||
|
_selectImage(fileName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildSelectImageButton() {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => selectImage(),
|
||||||
|
child: Container(
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blue.withAlpha(50),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.blue.withAlpha(80), width: 1),
|
||||||
|
),
|
||||||
|
child: Icon(Icons.photo_library_rounded, size: 20, color: Colors.blue),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildSelectTagButton() {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: _toggleTagOptions,
|
||||||
|
child: Container(
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.orange.withAlpha(50),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.orange.withAlpha(80), width: 1),
|
||||||
|
),
|
||||||
|
child: Icon(Icons.local_offer_rounded, size: 20, color: Colors.orange),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildConfirmButton() {
|
||||||
|
return Container(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
borderRadius: BorderRadius.circular(24),
|
||||||
|
),
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(Icons.arrow_forward_rounded, size: 24),
|
||||||
|
color: Colors.white,
|
||||||
|
onPressed: () => widget.onOk(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildShowTagOptions() {
|
||||||
|
// 计算弹窗位置(基于标签按钮位置)
|
||||||
|
return Positioned(
|
||||||
|
bottom: 50, // 调整垂直位置
|
||||||
|
left: 60, // 调整水平位置
|
||||||
|
child: Container(
|
||||||
|
width: 90,
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black26,
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children:
|
||||||
|
FlispTag.values.map((tag) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => _selectTag(tag),
|
||||||
|
child: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: tag.color,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: Icon(tag.icon, size: 12, color: Colors.white),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(tag.label, style: TextStyle(fontSize: 12)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildBottomButton() {
|
||||||
|
return Container(
|
||||||
|
padding: EdgeInsets.only(top: 16),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
buildSelectImageButton(),
|
||||||
|
SizedBox(width: 12),
|
||||||
|
buildSelectTagButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
buildConfirmButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final provider = Provider.of<FlispProvider>(context);
|
||||||
|
|
||||||
// 整体使用Stack布局分离事件层级
|
// 整体使用Stack布局分离事件层级
|
||||||
return Stack(
|
return Stack(
|
||||||
@@ -300,7 +289,9 @@ class _FlispFormState extends State<FlispForm> {
|
|||||||
// 主表单内容
|
// 主表单内容
|
||||||
FormBuilder(
|
FormBuilder(
|
||||||
key: widget.formKey,
|
key: widget.formKey,
|
||||||
child: Column(children: [buildFormBody(), buildBottomButton()]),
|
child: Column(
|
||||||
|
children: [buildFormBody(provider), buildBottomButton()],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// 标签弹窗(放在最上层,确保事件优先响应)
|
// 标签弹窗(放在最上层,确保事件优先响应)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'package:flisp_app/widgets/common.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
Widget buildFlispStatsCard(List<Flisp> flisps) {
|
Widget buildFlispStatsCard(BuildContext context, List<Flisp> flisps) {
|
||||||
int totalCount = flisps.length;
|
int totalCount = flisps.length;
|
||||||
|
|
||||||
int lifeCount = flisps.where((flisp) => flisp.tag == FlispTag.life).length;
|
int lifeCount = flisps.where((flisp) => flisp.tag == FlispTag.life).length;
|
||||||
@@ -15,16 +15,16 @@ Widget buildFlispStatsCard(List<Flisp> flisps) {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
_buildStatItem('总计', totalCount, Colors.orange),
|
_buildStatItem(context, '总计', totalCount),
|
||||||
_buildStatItem('生活', lifeCount, FlispTag.life.color),
|
_buildStatItem(context, '生活', lifeCount),
|
||||||
_buildStatItem('工作', workCount, FlispTag.work.color),
|
_buildStatItem(context, '工作', workCount),
|
||||||
_buildStatItem('学习', studyCount, FlispTag.study.color),
|
_buildStatItem(context, '学习', studyCount),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStatItem(String label, int count, Color color) {
|
Widget _buildStatItem(BuildContext context, String label, int count) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
@@ -32,7 +32,7 @@ Widget _buildStatItem(String label, int count, Color color) {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: color,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
@@ -209,13 +209,15 @@ Widget _buildFlispVideo(Flisp flisp) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildFlispTag(Flisp flisp) {
|
Widget buildFlispTag(BuildContext context, Flisp flisp) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: flisp.tag.color.withAlpha(30),
|
color: colors.secondaryContainer,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(color: flisp.tag.color.withAlpha(60)),
|
// border: Border.all(color: flisp.tag.color.withAlpha(60)),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -224,7 +226,7 @@ Widget buildFlispTag(Flisp flisp) {
|
|||||||
width: 14,
|
width: 14,
|
||||||
height: 14,
|
height: 14,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: flisp.tag.color,
|
color: colors.secondary,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
child: Icon(flisp.tag.icon, size: 8, color: Colors.white),
|
child: Icon(flisp.tag.icon, size: 8, color: Colors.white),
|
||||||
@@ -234,7 +236,7 @@ Widget buildFlispTag(Flisp flisp) {
|
|||||||
flisp.tag.label,
|
flisp.tag.label,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: flisp.tag.color,
|
color: colors.secondary,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -250,9 +252,13 @@ Widget buildFlispTime(Flisp flisp) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFlispSuffix(Flisp flisp) {
|
Widget _buildFlispSuffix(BuildContext context, Flisp flisp) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [buildFlispTag(flisp), const Spacer(), buildFlispTime(flisp)],
|
children: [
|
||||||
|
buildFlispTag(context, flisp),
|
||||||
|
const Spacer(),
|
||||||
|
buildFlispTime(flisp),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +287,7 @@ Widget _buildFlispItem({
|
|||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
if (hasVideo) _buildFlispVideo(flisp),
|
if (hasVideo) _buildFlispVideo(flisp),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
_buildFlispSuffix(flisp),
|
_buildFlispSuffix(context, flisp),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -22,350 +22,356 @@ class TodoForm extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TodoFormState extends State<TodoForm> {
|
class _TodoFormState extends State<TodoForm> {
|
||||||
|
final int maxTitleCount = 10;
|
||||||
|
final int maxContentCount = 20;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget buildTitle() {
|
||||||
Widget build(BuildContext context) {
|
return Row(
|
||||||
final int maxTitleCount = 10;
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
final int maxContentCount = 20;
|
children: [
|
||||||
final provider = Provider.of<TodoProvider>(context);
|
Icon(
|
||||||
|
widget.isEditing ? Icons.edit_note : Icons.add_task,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
widget.isEditing ? '编辑待办事项' : '添加待办事项',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBuilderTextField buildTitleField(TodoProvider provider) {
|
||||||
final colors = Theme.of(context).colorScheme;
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
Widget buildTitle() {
|
return FormBuilderTextField(
|
||||||
return Row(
|
name: 'title',
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
initialValue: provider.formItem.title,
|
||||||
children: [
|
onChanged: (value) {
|
||||||
Icon(
|
setState(() {
|
||||||
widget.isEditing ? Icons.edit_note : Icons.add_task,
|
provider.formItem.title = value ?? '';
|
||||||
color: colors.primary,
|
});
|
||||||
size: 24,
|
},
|
||||||
),
|
decoration: InputDecoration(
|
||||||
SizedBox(width: 8),
|
label: RichText(
|
||||||
Text(
|
text: TextSpan(
|
||||||
widget.isEditing ? '编辑待办事项' : '添加待办事项',
|
text: '标题',
|
||||||
style: TextStyle(
|
style: TextStyle(color: Colors.grey.shade700, fontSize: 16),
|
||||||
fontSize: 20,
|
children: const [
|
||||||
fontWeight: FontWeight.bold,
|
TextSpan(
|
||||||
color: colors.primary,
|
text: '*',
|
||||||
),
|
style: TextStyle(
|
||||||
),
|
color: Colors.red,
|
||||||
],
|
fontSize: 18,
|
||||||
);
|
fontWeight: FontWeight.bold,
|
||||||
}
|
|
||||||
|
|
||||||
FormBuilderTextField buildTitleField() {
|
|
||||||
return FormBuilderTextField(
|
|
||||||
name: 'title',
|
|
||||||
initialValue: provider.formItem.title,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.title = value ?? '';
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
label: RichText(
|
|
||||||
text: TextSpan(
|
|
||||||
text: '标题',
|
|
||||||
style: TextStyle(color: Colors.grey.shade700, fontSize: 16),
|
|
||||||
children: const [
|
|
||||||
TextSpan(
|
|
||||||
text: '*',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.red,
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
hintText: '请输入待办事项标题...',
|
|
||||||
hintStyle: TextStyle(color: Colors.grey),
|
|
||||||
counterText: '',
|
|
||||||
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: colors.primary),
|
|
||||||
),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
prefixIcon: Icon(Icons.title, color: Colors.blue),
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
),
|
||||||
maxLength: maxTitleCount,
|
hintText: '请输入待办事项标题...',
|
||||||
validator: (value) {
|
hintStyle: TextStyle(color: Colors.grey),
|
||||||
if (value == null || value.isEmpty) {
|
counterText: '',
|
||||||
return '请输入标题';
|
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
||||||
}
|
border: OutlineInputBorder(
|
||||||
if (value.length > maxTitleCount) {
|
|
||||||
return '标题不能超过$maxTitleCount个字符';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FormBuilderTextField buildContentField() {
|
|
||||||
return FormBuilderTextField(
|
|
||||||
name: 'content',
|
|
||||||
initialValue: provider.formItem.content,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.content = value ?? '';
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: '内容',
|
|
||||||
hintText: '请输入待办事项内容...',
|
|
||||||
hintStyle: TextStyle(color: Colors.grey),
|
|
||||||
counterText: '',
|
|
||||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: colors.primary),
|
|
||||||
),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
prefixIcon: Icon(Icons.description, color: Colors.green),
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
),
|
|
||||||
maxLines: 2,
|
|
||||||
maxLength: maxContentCount,
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null && value.length > maxContentCount) {
|
|
||||||
return '内容不能超过$maxContentCount个字符';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
IconButton buildClearDueDateSuffixIcon() {
|
|
||||||
return IconButton(
|
|
||||||
icon: Icon(Icons.clear, size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.dueDate = null;
|
|
||||||
});
|
|
||||||
widget.formKey.currentState?.fields['dueDate']?.didChange(null);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FormBuilderDateTimePicker buildDueDateField() {
|
|
||||||
return FormBuilderDateTimePicker(
|
|
||||||
name: 'dueDate',
|
|
||||||
format: DateFormat('yyyy-MM-dd'),
|
|
||||||
initialValue: provider.formItem.dueDate,
|
|
||||||
inputType: InputType.date,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.dueDate = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText:
|
|
||||||
provider.formItem.dueDate == null
|
|
||||||
? '选择截止日期'
|
|
||||||
: '截止: ${DateFormat('yyyy-MM-dd').format(provider.formItem.dueDate!)}',
|
|
||||||
labelStyle: TextStyle(
|
|
||||||
color:
|
|
||||||
provider.formItem.dueDate == null
|
|
||||||
? Colors.grey
|
|
||||||
: Colors.black87,
|
|
||||||
),
|
|
||||||
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: colors.primary),
|
|
||||||
),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
suffixIcon:
|
|
||||||
provider.formItem.dueDate != null
|
|
||||||
? buildClearDueDateSuffixIcon()
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null &&
|
|
||||||
value.isBefore(DateTime.now().subtract(Duration(days: 1)))) {
|
|
||||||
return '不能选择过去的日期';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
IconButton buildClearScheduledTimeSuffixIcon() {
|
|
||||||
return IconButton(
|
|
||||||
icon: Icon(Icons.clear, size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.scheduledTime = null;
|
|
||||||
});
|
|
||||||
widget.formKey.currentState?.fields['scheduledTime']?.didChange(null);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FormBuilderDateTimePicker buildScheduledTimeField() {
|
|
||||||
return FormBuilderDateTimePicker(
|
|
||||||
name: 'scheduledTime',
|
|
||||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
|
||||||
initialValue: provider.formItem.scheduledTime,
|
|
||||||
inputType: InputType.both,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.scheduledTime = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText:
|
|
||||||
provider.formItem.scheduledTime == null
|
|
||||||
? '选择提醒日期'
|
|
||||||
: '提醒: ${DateFormat('yyyy-MM-dd HH:mm:ss').format(provider.formItem.scheduledTime!)}',
|
|
||||||
labelStyle: TextStyle(
|
|
||||||
color:
|
|
||||||
provider.formItem.scheduledTime == null
|
|
||||||
? Colors.grey
|
|
||||||
: Colors.black87,
|
|
||||||
),
|
|
||||||
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: colors.primary),
|
|
||||||
),
|
|
||||||
filled: true,
|
|
||||||
fillColor: colors.surface,
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
||||||
suffixIcon:
|
|
||||||
provider.formItem.scheduledTime != null
|
|
||||||
? buildClearScheduledTimeSuffixIcon()
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value != null && value.isBefore(DateTime.now())) {
|
|
||||||
return '不能选择过去的日期';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FormBuilderRadioGroup builderRadioGroup() {
|
|
||||||
return FormBuilderRadioGroup<TodoPriority>(
|
|
||||||
name: 'priority',
|
|
||||||
initialValue: provider.formItem.priority,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
),
|
|
||||||
orientation: OptionsOrientation.horizontal,
|
|
||||||
wrapSpacing: 6,
|
|
||||||
options:
|
|
||||||
TodoPriority.values.map((priority) {
|
|
||||||
return FormBuilderFieldOption<TodoPriority>(
|
|
||||||
value: priority,
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [Text(priority.label)],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (value) {
|
|
||||||
if (value != null) {
|
|
||||||
setState(() {
|
|
||||||
provider.formItem.priority = value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Container buildPriorityField() {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: colors.surface,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(12),
|
enabledBorder: OutlineInputBorder(
|
||||||
child: Column(
|
borderRadius: BorderRadius.circular(12),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.flag, color: Colors.orange),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text('优先级'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
builderRadioGroup(),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
focusedBorder: OutlineInputBorder(
|
||||||
}
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
prefixIcon: Icon(Icons.title, color: Colors.blue),
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
maxLength: maxTitleCount,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return '请输入标题';
|
||||||
|
}
|
||||||
|
if (value.length > maxTitleCount) {
|
||||||
|
return '标题不能超过$maxTitleCount个字符';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
FormBuilder buildForm() {
|
FormBuilderTextField buildContentField(TodoProvider provider) {
|
||||||
return FormBuilder(
|
final colors = Theme.of(context).colorScheme;
|
||||||
key: widget.formKey,
|
|
||||||
child: Column(
|
return FormBuilderTextField(
|
||||||
mainAxisSize: MainAxisSize.min,
|
name: 'content',
|
||||||
children: [
|
initialValue: provider.formItem.content,
|
||||||
buildTitleField(),
|
onChanged: (value) {
|
||||||
SizedBox(height: 12),
|
setState(() {
|
||||||
buildContentField(),
|
provider.formItem.content = value ?? '';
|
||||||
SizedBox(height: 12),
|
});
|
||||||
buildDueDateField(),
|
},
|
||||||
SizedBox(height: 12),
|
decoration: InputDecoration(
|
||||||
buildScheduledTimeField(),
|
labelText: '内容',
|
||||||
SizedBox(height: 12),
|
hintText: '请输入待办事项内容...',
|
||||||
buildPriorityField(),
|
hintStyle: TextStyle(color: Colors.grey),
|
||||||
],
|
counterText: '',
|
||||||
|
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
),
|
),
|
||||||
);
|
enabledBorder: OutlineInputBorder(
|
||||||
}
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
prefixIcon: Icon(Icons.description, color: Colors.green),
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
maxLength: maxContentCount,
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null && value.length > maxContentCount) {
|
||||||
|
return '内容不能超过$maxContentCount个字符';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton buildClearDueDateSuffixIcon(TodoProvider provider) {
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(Icons.clear, size: 18),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.dueDate = null;
|
||||||
|
});
|
||||||
|
widget.formKey.currentState?.fields['dueDate']?.didChange(null);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBuilderDateTimePicker buildDueDateField(TodoProvider provider) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
return FormBuilderDateTimePicker(
|
||||||
|
name: 'dueDate',
|
||||||
|
format: DateFormat('yyyy-MM-dd'),
|
||||||
|
initialValue: provider.formItem.dueDate,
|
||||||
|
inputType: InputType.date,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.dueDate = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText:
|
||||||
|
provider.formItem.dueDate == null
|
||||||
|
? '选择截止日期'
|
||||||
|
: '截止: ${DateFormat('yyyy-MM-dd').format(provider.formItem.dueDate!)}',
|
||||||
|
labelStyle: TextStyle(
|
||||||
|
color:
|
||||||
|
provider.formItem.dueDate == null ? Colors.grey : Colors.black87,
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
suffixIcon:
|
||||||
|
provider.formItem.dueDate != null
|
||||||
|
? buildClearDueDateSuffixIcon(provider)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null &&
|
||||||
|
value.isBefore(DateTime.now().subtract(Duration(days: 1)))) {
|
||||||
|
return '不能选择过去的日期';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton buildClearScheduledTimeSuffixIcon(TodoProvider provider) {
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(Icons.clear, size: 18),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.scheduledTime = null;
|
||||||
|
});
|
||||||
|
widget.formKey.currentState?.fields['scheduledTime']?.didChange(null);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBuilderDateTimePicker buildScheduledTimeField(TodoProvider provider) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
return FormBuilderDateTimePicker(
|
||||||
|
name: 'scheduledTime',
|
||||||
|
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||||
|
initialValue: provider.formItem.scheduledTime,
|
||||||
|
inputType: InputType.both,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.scheduledTime = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText:
|
||||||
|
provider.formItem.scheduledTime == null
|
||||||
|
? '选择提醒日期'
|
||||||
|
: '提醒: ${DateFormat('yyyy-MM-dd HH:mm:ss').format(provider.formItem.scheduledTime!)}',
|
||||||
|
labelStyle: TextStyle(
|
||||||
|
color:
|
||||||
|
provider.formItem.scheduledTime == null
|
||||||
|
? Colors.grey
|
||||||
|
: Colors.black87,
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.calendar_month, color: Colors.purple),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surface,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
suffixIcon:
|
||||||
|
provider.formItem.scheduledTime != null
|
||||||
|
? buildClearScheduledTimeSuffixIcon(provider)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value != null && value.isBefore(DateTime.now())) {
|
||||||
|
return '不能选择过去的日期';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBuilderRadioGroup builderRadioGroup(TodoProvider provider) {
|
||||||
|
return FormBuilderRadioGroup<TodoPriority>(
|
||||||
|
name: 'priority',
|
||||||
|
initialValue: provider.formItem.priority,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
),
|
||||||
|
orientation: OptionsOrientation.horizontal,
|
||||||
|
wrapSpacing: 6,
|
||||||
|
options:
|
||||||
|
TodoPriority.values.map((priority) {
|
||||||
|
return FormBuilderFieldOption<TodoPriority>(
|
||||||
|
value: priority,
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [Text(priority.label)],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value != null) {
|
||||||
|
setState(() {
|
||||||
|
provider.formItem.priority = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Container buildPriorityField(TodoProvider provider) {
|
||||||
|
return Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.flag, color: Colors.orange),
|
||||||
|
SizedBox(width: 6),
|
||||||
|
Text('优先级'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
builderRadioGroup(provider),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBuilder buildForm(TodoProvider provider) {
|
||||||
|
return FormBuilder(
|
||||||
|
key: widget.formKey,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
buildTitleField(provider),
|
||||||
|
SizedBox(height: 12),
|
||||||
|
buildContentField(provider),
|
||||||
|
SizedBox(height: 12),
|
||||||
|
buildDueDateField(provider),
|
||||||
|
SizedBox(height: 12),
|
||||||
|
buildScheduledTimeField(provider),
|
||||||
|
SizedBox(height: 12),
|
||||||
|
buildPriorityField(provider),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final provider = Provider.of<TodoProvider>(context);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [buildTitle(), SizedBox(height: 20), buildForm()],
|
children: [buildTitle(), SizedBox(height: 20), buildForm(provider)],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
// 统计卡片
|
// 统计卡片
|
||||||
Widget buildTodoStatsCard(List<Todo> todos) {
|
Widget buildTodoStatsCard(BuildContext context, List<Todo> todos) {
|
||||||
int totalCount = todos.length;
|
int totalCount = todos.length;
|
||||||
|
|
||||||
int activeCount = todos.where((todo) => !todo.isCompleted).length;
|
int activeCount = todos.where((todo) => !todo.isCompleted).length;
|
||||||
@@ -17,15 +17,15 @@ Widget buildTodoStatsCard(List<Todo> todos) {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
_buildStatItem('总计', totalCount, Colors.blue),
|
_buildStatItem(context, '总计', totalCount),
|
||||||
_buildStatItem('待完成', activeCount, Colors.orange),
|
_buildStatItem(context, '待完成', activeCount),
|
||||||
_buildStatItem('已完成', completedCount, Colors.green),
|
_buildStatItem(context, '已完成', completedCount),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStatItem(String label, int count, Color color) {
|
Widget _buildStatItem(BuildContext context, String label, int count) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
@@ -33,7 +33,7 @@ Widget _buildStatItem(String label, int count, Color color) {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: color,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class _YearSelectorState extends State<YearSelector>
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user