feat:增加主题色存储本地的功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toggle_switch/toggle_switch.dart';
|
||||
|
||||
BoxDecoration buildBoxDecoration() {
|
||||
return BoxDecoration(
|
||||
@@ -8,6 +9,7 @@ BoxDecoration buildBoxDecoration() {
|
||||
);
|
||||
}
|
||||
|
||||
// 卡片
|
||||
class BuildCard extends StatelessWidget {
|
||||
final Widget? child;
|
||||
|
||||
@@ -29,6 +31,7 @@ class BuildCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// 底部弹出
|
||||
void buildModalBottom({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
@@ -113,3 +116,86 @@ Widget buildModalBottomBody(BuildContext context, String title, Widget body) {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 滑动删除
|
||||
Widget buildDismissible({
|
||||
required BuildContext context,
|
||||
required Object id,
|
||||
required Widget child,
|
||||
required VoidCallback onDelete,
|
||||
}) {
|
||||
return Dismissible(
|
||||
key: ValueKey(id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: _buildDismissBackground(),
|
||||
confirmDismiss: (direction) async {
|
||||
// 这里实现二次确认
|
||||
return await _showDeleteConfirmationDialog(context);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
onDelete();
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
// 确认对话框
|
||||
Future<bool?> _showDeleteConfirmationDialog(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('确认删除'),
|
||||
backgroundColor: Colors.white,
|
||||
content: const Text('确定要删除这个项目吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDismissBackground() {
|
||||
return Container(
|
||||
color: Colors.red,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: const Icon(Icons.delete, color: Colors.white, size: 24),
|
||||
);
|
||||
}
|
||||
|
||||
// toggle切换
|
||||
Widget buildToggleSwitch<T extends Enum>({
|
||||
required BuildContext context,
|
||||
required T currentTab,
|
||||
required List<T> tabValues,
|
||||
required List<String> labels,
|
||||
required ValueChanged<T> onTabChanged,
|
||||
}) {
|
||||
return ToggleSwitch(
|
||||
minWidth: 90.0,
|
||||
minHeight: 40.0,
|
||||
initialLabelIndex: tabValues.indexOf(currentTab),
|
||||
totalSwitches: tabValues.length,
|
||||
labels: labels,
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.grey.shade200,
|
||||
inactiveFgColor: Colors.grey.shade700,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
onToggle: (index) {
|
||||
if (index != null && index < tabValues.length) {
|
||||
onTabChanged(tabValues[index]);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ class _FlispFormState extends State<FlispForm> {
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: '记录你的灵感瞬间...',
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
counterText: '',
|
||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||
border: OutlineInputBorder(
|
||||
|
||||
@@ -48,23 +48,12 @@ Widget buildTabs({
|
||||
}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: ToggleSwitch(
|
||||
minWidth: 90.0,
|
||||
minHeight: 40.0,
|
||||
initialLabelIndex: FlispTab.values.indexOf(currentTab),
|
||||
totalSwitches: FlispTab.values.length,
|
||||
child: buildToggleSwitch(
|
||||
context: context,
|
||||
currentTab: currentTab,
|
||||
tabValues: FlispTab.values,
|
||||
labels: FlispTab.values.map((e) => e.label).toList(),
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.grey.shade200,
|
||||
inactiveFgColor: Colors.grey.shade700,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
onToggle: (index) {
|
||||
if (index != null) {
|
||||
onTabChanged(FlispTab.values[index]);
|
||||
}
|
||||
},
|
||||
onTabChanged: onTabChanged,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -275,17 +264,10 @@ Widget _buildFlispItem({
|
||||
final hasImage = flisp.imageUrl.isNotEmpty;
|
||||
final hasVideo = flisp.videoUrl.isNotEmpty;
|
||||
|
||||
return Dismissible(
|
||||
key: ValueKey(flisp.id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: _buildDismissBackground(),
|
||||
confirmDismiss: (direction) async {
|
||||
// 这里实现二次确认
|
||||
return await _showDeleteConfirmationDialog(context);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
onDelete(flisp);
|
||||
},
|
||||
return buildDismissible(
|
||||
context: context,
|
||||
id: flisp.id,
|
||||
onDelete: () => onDelete(flisp),
|
||||
child: BuildCard(
|
||||
child: InkWell(
|
||||
onTap: () => onEdit(flisp),
|
||||
@@ -306,39 +288,6 @@ Widget _buildFlispItem({
|
||||
);
|
||||
}
|
||||
|
||||
// 确认对话框
|
||||
Future<bool?> _showDeleteConfirmationDialog(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('确认删除'),
|
||||
backgroundColor: Colors.white,
|
||||
content: const Text('确定要删除这个项目吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDismissBackground() {
|
||||
return Container(
|
||||
color: Colors.red,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: const Icon(Icons.delete, color: Colors.white, size: 24),
|
||||
);
|
||||
}
|
||||
|
||||
// 空状态
|
||||
Widget buildEmptyState(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
@@ -82,6 +82,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
),
|
||||
),
|
||||
hintText: '请输入待办事项标题...',
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
counterText: '',
|
||||
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
||||
border: OutlineInputBorder(
|
||||
@@ -126,6 +127,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
decoration: InputDecoration(
|
||||
labelText: '内容',
|
||||
hintText: '请输入待办事项内容...',
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
counterText: '',
|
||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||
border: OutlineInputBorder(
|
||||
|
||||
@@ -50,31 +50,22 @@ Widget buildTabs({
|
||||
}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: ToggleSwitch(
|
||||
minWidth: 90.0,
|
||||
minHeight: 40.0,
|
||||
initialLabelIndex: TodoTab.values.indexOf(currentTab),
|
||||
totalSwitches: TodoTab.values.length,
|
||||
child: buildToggleSwitch(
|
||||
context: context,
|
||||
currentTab: currentTab,
|
||||
tabValues: TodoTab.values,
|
||||
labels: TodoTab.values.map((e) => e.label).toList(),
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.grey.shade200,
|
||||
inactiveFgColor: Colors.grey.shade700,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
onToggle: (index) {
|
||||
if (index != null) {
|
||||
onTabChanged(TodoTab.values[index]);
|
||||
}
|
||||
},
|
||||
onTabChanged: onTabChanged,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTodoList({
|
||||
required BuildContext context,
|
||||
required List<Todo> todos,
|
||||
required ValueChanged<Todo> onToggleTodo,
|
||||
required ValueChanged<Todo> onEditTodo,
|
||||
required ValueChanged<Todo> onDelete,
|
||||
}) {
|
||||
return ListView.separated(
|
||||
itemCount: todos.length,
|
||||
@@ -82,35 +73,44 @@ Widget buildTodoList({
|
||||
itemBuilder: (context, index) {
|
||||
final todo = todos[index];
|
||||
return _buildTodoItem(
|
||||
context: context,
|
||||
todo: todo,
|
||||
onToggle: onToggleTodo,
|
||||
onEdit: onEditTodo,
|
||||
onDelete: onDelete,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodoItem({
|
||||
required BuildContext context,
|
||||
required Todo todo,
|
||||
required ValueChanged<Todo> onToggle,
|
||||
required ValueChanged<Todo> onEdit,
|
||||
required ValueChanged<Todo> onDelete,
|
||||
}) {
|
||||
return BuildCard(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0),
|
||||
leading: SizedBox(
|
||||
width: 24,
|
||||
child: Checkbox(
|
||||
value: todo.isCompleted,
|
||||
onChanged: (value) => onToggle(todo),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
return buildDismissible(
|
||||
context: context,
|
||||
id: todo.id,
|
||||
onDelete: () => onDelete(todo),
|
||||
child: BuildCard(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0),
|
||||
leading: SizedBox(
|
||||
width: 24,
|
||||
child: Checkbox(
|
||||
value: todo.isCompleted,
|
||||
onChanged: (value) => onToggle(todo),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
title: _buildTodoTitle(todo),
|
||||
subtitle: _buildTodoSubtitle(todo),
|
||||
trailing: _buildPriorityBadge(todo.priority),
|
||||
onTap: () => onEdit(todo),
|
||||
// onLongPress: () => onShowOptions(todo),
|
||||
),
|
||||
title: _buildTodoTitle(todo),
|
||||
subtitle: _buildTodoSubtitle(todo),
|
||||
trailing: _buildPriorityBadge(todo.priority),
|
||||
onTap: () => onEdit(todo),
|
||||
// onLongPress: () => onShowOptions(todo),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user