import 'package:flisp_app/layout/app_drawer.dart'; import 'package:flisp_app/pages/flisp_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 createState() => _MainScreenState(); } class _MainScreenState extends State { final GlobalKey _flispPageKey = GlobalKey(); final GlobalKey _todoPageKey = GlobalKey(); List navItems = [ BottomNavigationBarItem(icon: Icon(Icons.flash_on), label: '闪灵'), BottomNavigationBarItem(icon: Icon(Icons.checklist), label: '待办'), ]; @override Widget build(BuildContext context) { return Consumer( builder: (context, appProvider, child) { return Scaffold( drawer: const AppDrawer(), appBar: AppBar( title: Text(_getAppBarTitle(appProvider.currentIndex)), backgroundColor: Colors.blue, foregroundColor: Colors.white, elevation: 0, ), body: _buildPage(appProvider.currentIndex), bottomNavigationBar: BottomNavigationBar( currentIndex: appProvider.currentIndex, onTap: (index) => appProvider.changeTab(index), type: BottomNavigationBarType.fixed, backgroundColor: Colors.white, items: navItems, ), floatingActionButton: _buildFloatingButton(appProvider.currentIndex), ); }, ); } 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(); } } } 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) { switch (index) { case 0: return FlispPage(key: _flispPageKey); case 1: return TodoPage(key: _todoPageKey); default: return FlispPage(key: _flispPageKey); } } String _getAppBarTitle(int index) { final titles = {0: '闪灵', 1: '待办'}; return titles[index] ?? '闪灵'; } }