feat:增加删除闪灵功能
This commit is contained in:
@@ -43,7 +43,7 @@ class FlispPageState extends State<FlispPage> {
|
|||||||
return buildBody(
|
return buildBody(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// 选项卡
|
buildStatsCard(_activeFlisps),
|
||||||
buildTabs(
|
buildTabs(
|
||||||
currentTab: _currentTab,
|
currentTab: _currentTab,
|
||||||
onTabChanged: (value) {
|
onTabChanged: (value) {
|
||||||
@@ -63,10 +63,14 @@ class FlispPageState extends State<FlispPage> {
|
|||||||
return _activeFlisps.isEmpty
|
return _activeFlisps.isEmpty
|
||||||
? buildEmptyState()
|
? buildEmptyState()
|
||||||
: buildFlispList(
|
: buildFlispList(
|
||||||
|
context: context,
|
||||||
flisps: _activeFlisps,
|
flisps: _activeFlisps,
|
||||||
onEdit: (flisp) {
|
onEdit: (flisp) {
|
||||||
_showDialog(true, flisp);
|
_showDialog(true, flisp);
|
||||||
},
|
},
|
||||||
|
onDelete: (flisp) {
|
||||||
|
_deleteFlisp(flisp);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +103,6 @@ class FlispPageState extends State<FlispPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存待办事项
|
|
||||||
void _saveFlisp(bool isEditing, Flisp flisp) async {
|
void _saveFlisp(bool isEditing, Flisp flisp) async {
|
||||||
late bool isSuccess;
|
late bool isSuccess;
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
@@ -118,4 +121,18 @@ class FlispPageState extends State<FlispPage> {
|
|||||||
showErrorDialog(context, isEditing ? '更新失败' : '添加失败');
|
showErrorDialog(context, isEditing ? '更新失败' : '添加失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _deleteFlisp(Flisp flisp) async {
|
||||||
|
bool isSuccess = await flispService.deleteFlisp(flisp);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_flisps = flispService.getAllFlisps();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
showSuccessDialog(context, '删除成功');
|
||||||
|
} else {
|
||||||
|
showErrorDialog(context, '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ class TodoPageState extends State<TodoPage> {
|
|||||||
return buildBody(
|
return buildBody(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// 统计信息卡片
|
|
||||||
buildStatsCard(_todos),
|
buildStatsCard(_todos),
|
||||||
// 选项卡
|
|
||||||
buildTabs(
|
buildTabs(
|
||||||
currentTab: _currentTab,
|
currentTab: _currentTab,
|
||||||
onTabChanged: (value) {
|
onTabChanged: (value) {
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import 'package:flisp_app/models/flisp.dart';
|
|||||||
List<Flisp> getActiveFlisps(FlispTab currentTab, List<Flisp> flisps) {
|
List<Flisp> getActiveFlisps(FlispTab currentTab, List<Flisp> flisps) {
|
||||||
switch (currentTab) {
|
switch (currentTab) {
|
||||||
case FlispTab.life:
|
case FlispTab.life:
|
||||||
return flisps.where((flisp) => flisp.tag == FlispTab.life).toList();
|
return flisps.where((flisp) => flisp.tag.label == FlispTab.life.label).toList();
|
||||||
case FlispTab.work:
|
case FlispTab.work:
|
||||||
return flisps.where((flisp) => flisp.tag == FlispTab.work).toList();
|
return flisps.where((flisp) => flisp.tag.label == FlispTab.work.label).toList();
|
||||||
case FlispTab.study:
|
case FlispTab.study:
|
||||||
return flisps.where((flisp) => flisp.tag == FlispTab.study).toList();
|
return flisps.where((flisp) => flisp.tag.label == FlispTab.study.label).toList();
|
||||||
default:
|
default:
|
||||||
return flisps;
|
return flisps;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Container buildBody({Widget? child}) {
|
|||||||
Container buildCard({Widget? child}) {
|
Container buildCard({Widget? child}) {
|
||||||
return Container(
|
return Container(
|
||||||
decoration: buildBoxDecoration(),
|
decoration: buildBoxDecoration(),
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(10),
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,43 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:toggle_switch/toggle_switch.dart';
|
import 'package:toggle_switch/toggle_switch.dart';
|
||||||
|
|
||||||
|
Widget buildStatsCard(List<Flisp> flisps) {
|
||||||
|
int totalCount = flisps.length;
|
||||||
|
|
||||||
|
int lifeCount = flisps.where((flisp) => flisp.tag == FlispTag.life).length;
|
||||||
|
int workCount = flisps.where((flisp) => flisp.tag == FlispTag.work).length;
|
||||||
|
int studyCount = flisps.where((flisp) => flisp.tag == FlispTag.study).length;
|
||||||
|
|
||||||
|
return buildCard(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
_buildStatItem('总计', totalCount, Colors.orange),
|
||||||
|
_buildStatItem('生活', lifeCount, FlispTag.life.color),
|
||||||
|
_buildStatItem('工作', workCount, FlispTag.work.color),
|
||||||
|
_buildStatItem('学习', studyCount, FlispTag.study.color),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStatItem(String label, int count, Color color) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
count.toString(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: color,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildTabs({
|
Widget buildTabs({
|
||||||
required FlispTab currentTab,
|
required FlispTab currentTab,
|
||||||
required ValueChanged<FlispTab> onTabChanged,
|
required ValueChanged<FlispTab> onTabChanged,
|
||||||
@@ -32,15 +69,22 @@ Widget buildTabs({
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildFlispList({
|
Widget buildFlispList({
|
||||||
|
required BuildContext context,
|
||||||
required List<Flisp> flisps,
|
required List<Flisp> flisps,
|
||||||
required ValueChanged<Flisp> onEdit,
|
required ValueChanged<Flisp> onEdit,
|
||||||
|
required ValueChanged<Flisp> onDelete,
|
||||||
}) {
|
}) {
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
itemCount: flisps.length,
|
itemCount: flisps.length,
|
||||||
separatorBuilder: (context, index) => SizedBox(height: 8),
|
separatorBuilder: (context, index) => SizedBox(height: 8),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final flisp = flisps[index];
|
final flisp = flisps[index];
|
||||||
return _buildFlispItem(flisp: flisp, onEdit: onEdit);
|
return _buildFlispItem(
|
||||||
|
context: context,
|
||||||
|
flisp: flisp,
|
||||||
|
onEdit: onEdit,
|
||||||
|
onDelete: onDelete,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -180,31 +224,80 @@ Widget _buildFlispSuffix(Flisp flisp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFlispItem({
|
Widget _buildFlispItem({
|
||||||
|
required BuildContext context,
|
||||||
required Flisp flisp,
|
required Flisp flisp,
|
||||||
required ValueChanged<Flisp> onEdit,
|
required ValueChanged<Flisp> onEdit,
|
||||||
|
required ValueChanged<Flisp> onDelete,
|
||||||
}) {
|
}) {
|
||||||
final hasImage = flisp.imageUrl.isNotEmpty;
|
final hasImage = flisp.imageUrl.isNotEmpty;
|
||||||
final hasVideo = flisp.videoUrl.isNotEmpty;
|
final hasVideo = flisp.videoUrl.isNotEmpty;
|
||||||
|
|
||||||
return buildCard(
|
return Dismissible(
|
||||||
child: InkWell(
|
key: ValueKey(flisp.id),
|
||||||
onTap: () => onEdit(flisp),
|
direction: DismissDirection.endToStart,
|
||||||
child: Column(
|
background: _buildDismissBackground(),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
confirmDismiss: (direction) async {
|
||||||
children: [
|
// 这里实现二次确认
|
||||||
_buildFlispContent(flisp),
|
return await _showDeleteConfirmationDialog(context);
|
||||||
const SizedBox(height: 8),
|
},
|
||||||
if (hasImage) _buildFlispImage(flisp),
|
onDismissed: (direction) {
|
||||||
const SizedBox(height: 4),
|
onDelete(flisp);
|
||||||
if (hasVideo) _buildFlispVideo(flisp),
|
},
|
||||||
const SizedBox(height: 4),
|
child: Container(
|
||||||
_buildFlispSuffix(flisp),
|
decoration: buildBoxDecoration(),
|
||||||
],
|
padding: EdgeInsets.all(16),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => onEdit(flisp),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
_buildFlispContent(flisp),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
if (hasImage) _buildFlispImage(flisp),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
if (hasVideo) _buildFlispVideo(flisp),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
_buildFlispSuffix(flisp),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确认对话框
|
||||||
|
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() {
|
Widget buildEmptyState() {
|
||||||
return Center(
|
return Center(
|
||||||
|
|||||||
Reference in New Issue
Block a user