banxiang/lib/screens/main_screen.dart

65 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'home_screen.dart';
import 'services_screen.dart';
import 'ai_chat_screen.dart';
import 'messages_screen.dart';
import 'profile_screen.dart';
import 'create_activity_screen.dart';
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
int _currentIndex = 0;
final _screens = [
HomeScreen(),
ServicesScreen(),
AiChatScreen(),
MessagesScreen(),
ProfileScreen(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(index: _currentIndex, children: _screens),
floatingActionButton: _buildGlobalFab(),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (i) => setState(() => _currentIndex = i),
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home_outlined), activeIcon: Icon(Icons.home), label: '首页'),
BottomNavigationBarItem(icon: Icon(Icons.grid_view_outlined), activeIcon: Icon(Icons.grid_view), label: '服务'),
BottomNavigationBarItem(icon: Icon(Icons.smart_toy_outlined), activeIcon: Icon(Icons.smart_toy), label: 'AI管家'),
BottomNavigationBarItem(icon: Icon(Icons.message_outlined), activeIcon: Icon(Icons.message), label: '消息'),
BottomNavigationBarItem(icon: Icon(Icons.person_outline), activeIcon: Icon(Icons.person), label: '我的'),
],
),
);
}
Widget? _buildGlobalFab() {
if (_currentIndex == 0) {
return null;
}
return FloatingActionButton.extended(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (_) => CreateActivityScreen()),
);
},
icon: const Icon(Icons.add),
label: const Text('发起活动', style: TextStyle(fontSize: 16)),
backgroundColor: const Color(0xFF1976D2),
foregroundColor: Colors.white,
);
}
}