feat:重构代办事项模块

This commit is contained in:
2025-11-06 23:52:20 +08:00
parent 6c3d2c9099
commit 783fd67398
11 changed files with 751 additions and 689 deletions

View File

@@ -7,29 +7,29 @@ import 'package:flisp_app/provider/app_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class MainScreen extends StatelessWidget {
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
final GlobalKey<TodoPageState> _todoPageKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Consumer<AppProvider>(
builder: (context, appState, child) {
return Scaffold(
// 侧边抽屉菜单
drawer: const AppDrawer(),
// 顶部导航栏
appBar: AppBar(
title: const Text('闪灵'),
title: Text(_getAppBarTitle(appState.currentIndex)),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
elevation: 0,
),
// 主体内容
body: _buildPage(appState.currentIndex),
// 底部导航栏
bottomNavigationBar: BottomNavigationBar(
currentIndex: appState.currentIndex,
onTap: (index) => appState.changeTab(index),
@@ -53,12 +53,50 @@ class MainScreen extends StatelessWidget {
),
],
),
floatingActionButton: _buildFloatingActionButton(appState.currentIndex),
);
},
);
}
// 根据索引构建对应页面
Widget? _buildFloatingActionButton(int currentIndex) {
if (currentIndex == 2) {
return FloatingActionButton(
onPressed: _showAddTodoDialog,
backgroundColor: Colors.transparent,
elevation: 0,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [Colors.orange.shade300, Colors.orange.shade500],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
boxShadow: [
BoxShadow(
color: Colors.orange.shade100,
blurRadius: 12,
offset: Offset(0, 6),
),
],
),
child: Icon(Icons.add, color: Colors.white, size: 36),
),
);
}
return null;
}
void _showAddTodoDialog() {
// 通过 GlobalKey 调用 TodoPage 的方法
if (_todoPageKey.currentState != null) {
_todoPageKey.currentState!.showAddTodoDialog();
}
}
Widget _buildPage(int index) {
switch (index) {
case 0:
@@ -66,11 +104,21 @@ class MainScreen extends StatelessWidget {
case 1:
return const NotesPage();
case 2:
return const TodoPage();
return TodoPage(key: _todoPageKey); // 传递 key
case 3:
return const RemindersPage();
default:
return const FlashPage();
}
}
String _getAppBarTitle(int index) {
final titles = {
0: '闪灵',
1: '笔记',
2: '待办事项',
3: '提醒任务',
};
return titles[index] ?? '闪灵';
}
}