134 lines
4.2 KiB
Dart
134 lines
4.2 KiB
Dart
import 'package:flisp_app/layout/app_drawer.dart';
|
|
import 'package:flisp_app/pages/calendar_page.dart';
|
|
import 'package:flisp_app/pages/flisp_page.dart';
|
|
import 'package:flisp_app/pages/stats_page.dart';
|
|
import 'package:flisp_app/pages/todo_page.dart';
|
|
import 'package:flisp_app/provider/app_provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class MainScreen extends StatefulWidget {
|
|
const MainScreen({super.key});
|
|
|
|
@override
|
|
State<MainScreen> createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends State<MainScreen> {
|
|
final GlobalKey<FlispPageState> _flispPageKey = GlobalKey();
|
|
final GlobalKey<TodoPageState> _todoPageKey = GlobalKey();
|
|
final GlobalKey<CalendarPageState> _calendarPageKey = GlobalKey();
|
|
|
|
List<BottomNavigationBarItem> navItems = [
|
|
BottomNavigationBarItem(icon: Icon(Icons.flash_on), label: '闪灵'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.checklist), label: '待办'),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.calendar_month_rounded),
|
|
label: '日程',
|
|
),
|
|
BottomNavigationBarItem(icon: Icon(Icons.insert_chart), label: '统计'),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<AppProvider>(
|
|
builder: (context, appProvider, child) {
|
|
return Scaffold(
|
|
drawer: const AppDrawer(),
|
|
appBar: AppBar(
|
|
title: Text(_getAppBarTitle(appProvider.currentTab)),
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
|
elevation: 0,
|
|
),
|
|
body: _buildPage(appProvider.currentTab),
|
|
bottomNavigationBar: Container(
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Theme.of(context).colorScheme.shadow.withAlpha(20),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, -2),
|
|
),
|
|
],
|
|
),
|
|
child: BottomNavigationBar(
|
|
currentIndex: appProvider.currentTab,
|
|
onTap: (index) => appProvider.changeTab(index),
|
|
type: BottomNavigationBarType.fixed,
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
selectedItemColor: Theme.of(context).colorScheme.primary,
|
|
unselectedItemColor: Theme.of(
|
|
context,
|
|
).colorScheme.onSurface.withAlpha(120),
|
|
showSelectedLabels: true,
|
|
showUnselectedLabels: true,
|
|
items: navItems,
|
|
),
|
|
),
|
|
floatingActionButton: _buildFloatingButton(
|
|
context,
|
|
appProvider.currentTab,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _onPressFloatingButton(int index) {
|
|
if (index == 0) {
|
|
if (_flispPageKey.currentState != null) {
|
|
_flispPageKey.currentState!.showAddDialog();
|
|
}
|
|
} else if (index == 1) {
|
|
if (_todoPageKey.currentState != null) {
|
|
_todoPageKey.currentState!.showAddDialog();
|
|
}
|
|
} else if (index == 2) {
|
|
if (_calendarPageKey.currentState != null) {
|
|
_calendarPageKey.currentState!.showAddDialog();
|
|
}
|
|
}
|
|
}
|
|
|
|
Widget? _buildFloatingButton(BuildContext context, int index) {
|
|
if (index == 3) return null;
|
|
|
|
return FloatingActionButton(
|
|
onPressed: () => _onPressFloatingButton(index),
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
shape: CircleBorder(),
|
|
child: Container(
|
|
width: 50,
|
|
height: 50,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
child: Icon(Icons.add, color: Colors.white, size: 36),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildPage(int index) {
|
|
switch (index) {
|
|
case 0:
|
|
return FlispPage(key: _flispPageKey);
|
|
case 1:
|
|
return TodoPage(key: _todoPageKey);
|
|
case 2:
|
|
return CalendarPage(key: _calendarPageKey);
|
|
case 3:
|
|
return StatsPage();
|
|
default:
|
|
return FlispPage(key: _flispPageKey);
|
|
}
|
|
}
|
|
|
|
String _getAppBarTitle(int index) {
|
|
final titles = {0: '闪灵', 1: '待办', 2: '日程', 3: '统计'};
|
|
return titles[index] ?? '闪灵';
|
|
}
|
|
}
|