feat:更新待办事项对话框功能
This commit is contained in:
@@ -17,84 +17,74 @@ class MainScreen extends StatefulWidget {
|
||||
class _MainScreenState extends State<MainScreen> {
|
||||
final GlobalKey<TodoPageState> _todoPageKey = GlobalKey();
|
||||
|
||||
List<BottomNavigationBarItem> navItems = [
|
||||
BottomNavigationBarItem(icon: Icon(Icons.flash_on), label: '闪灵'),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.note), label: '笔记'),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.checklist), label: '待办'),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.notifications), label: '提醒'),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<AppProvider>(
|
||||
builder: (context, appState, child) {
|
||||
builder: (context, appProvider, child) {
|
||||
return Scaffold(
|
||||
drawer: const AppDrawer(),
|
||||
appBar: AppBar(
|
||||
title: Text(_getAppBarTitle(appState.currentIndex)),
|
||||
title: Text(_getAppBarTitle(appProvider.currentIndex)),
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: _buildPage(appState.currentIndex),
|
||||
body: _buildPage(appProvider.currentIndex),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: appState.currentIndex,
|
||||
onTap: (index) => appState.changeTab(index),
|
||||
currentIndex: appProvider.currentIndex,
|
||||
onTap: (index) => appProvider.changeTab(index),
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.flash_on),
|
||||
label: '闪灵',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.note),
|
||||
label: '笔记',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.checklist),
|
||||
label: '待办',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.notifications),
|
||||
label: '提醒',
|
||||
),
|
||||
],
|
||||
backgroundColor: Colors.white,
|
||||
items: navItems,
|
||||
),
|
||||
floatingActionButton: _buildFloatingActionButton(appState.currentIndex),
|
||||
floatingActionButton: _buildFloatingButton(appProvider.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),
|
||||
),
|
||||
);
|
||||
void _onPressFloatingButton(int index) {
|
||||
if (index == 2) {
|
||||
if (_todoPageKey.currentState != null) {
|
||||
_todoPageKey.currentState!.showAddTodoDialog();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _showAddTodoDialog() {
|
||||
// 通过 GlobalKey 调用 TodoPage 的方法
|
||||
if (_todoPageKey.currentState != null) {
|
||||
_todoPageKey.currentState!.showAddTodoDialog();
|
||||
}
|
||||
Widget _buildFloatingButton(int index) {
|
||||
return FloatingActionButton(
|
||||
onPressed: () => _onPressFloatingButton(index),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
shape: CircleBorder(),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage(int index) {
|
||||
@@ -113,12 +103,7 @@ class _MainScreenState extends State<MainScreen> {
|
||||
}
|
||||
|
||||
String _getAppBarTitle(int index) {
|
||||
final titles = {
|
||||
0: '闪灵',
|
||||
1: '笔记',
|
||||
2: '待办事项',
|
||||
3: '提醒任务',
|
||||
};
|
||||
final titles = {0: '闪灵', 1: '笔记', 2: '待办', 3: '提醒'};
|
||||
return titles[index] ?? '闪灵';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user