fix: 修复底部导航栏被覆盖和FAB消失问题

This commit is contained in:
Ubuntu 2026-02-20 01:23:49 +08:00
parent f4c5369792
commit c87a6756db
3 changed files with 64 additions and 32 deletions

View File

@ -13,6 +13,7 @@ class ActivityListScreen extends StatefulWidget {
class _ActivityListScreenState extends State<ActivityListScreen> { class _ActivityListScreenState extends State<ActivityListScreen> {
int _selectedIndex = 0; int _selectedIndex = 0;
bool _showFriendsOverlay = false;
final _feedKey = GlobalKey<RefreshIndicatorState>(); final _feedKey = GlobalKey<RefreshIndicatorState>();
String? _selectedTime; String? _selectedTime;
@ -83,10 +84,6 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
} }
void _onItemTapped(int index) { void _onItemTapped(int index) {
if (index == 0 && _selectedIndex == 0) {
_feedKey.currentState?.show();
return;
}
if (index == 2) { if (index == 2) {
// - // -
Navigator.push( Navigator.push(
@ -95,24 +92,26 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
); );
return; return;
} }
if (index == 1) { if (index == 1) {
Navigator.push( setState(() {
context, _showFriendsOverlay = !_showFriendsOverlay;
MaterialPageRoute(builder: (context) => const FriendsScreen()), if (_showFriendsOverlay) {
); _selectedIndex = 0;
}
});
return; return;
} }
if (index == 3 || index == 4) {
if (_selectedIndex != index) { if (index == 0 && _selectedIndex == 0 && !_showFriendsOverlay) {
setState(() { _feedKey.currentState?.show();
_selectedIndex = index;
});
}
return; return;
} }
if (_selectedIndex != index) {
if (_selectedIndex != index || _showFriendsOverlay) {
setState(() { setState(() {
_selectedIndex = index; _selectedIndex = index;
_showFriendsOverlay = false;
}); });
} }
} }
@ -123,27 +122,29 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
if (_selectedIndex == 3 || _selectedIndex == 4) { if (_selectedIndex == 3 || _selectedIndex == 4) {
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFFFF8F0), backgroundColor: const Color(0xFFFFF8F0),
body: _buildBody(), body: _buildBodyWithFriendsOverlay(),
bottomNavigationBar: _buildBottomNavigationBar(), bottomNavigationBar: _buildBottomNavigationBar(),
); );
} }
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFFFF8F0), backgroundColor: const Color(0xFFFFF8F0),
appBar: AppBar( appBar: _showFriendsOverlay
title: Text('伴享', style: TextStyle(fontWeight: FontWeight.bold)), ? null
centerTitle: true, : AppBar(
actions: [ title: Text('伴享', style: TextStyle(fontWeight: FontWeight.bold)),
IconButton( centerTitle: true,
icon: Icon(Icons.search), actions: [
onPressed: () {}, IconButton(
), icon: Icon(Icons.search),
IconButton( onPressed: () {},
icon: Icon(Icons.notifications_none), ),
onPressed: () {}, IconButton(
), icon: Icon(Icons.notifications_none),
], onPressed: () {},
), ),
body: _buildBody(), ],
),
body: _buildBodyWithFriendsOverlay(),
bottomNavigationBar: _buildBottomNavigationBar(), bottomNavigationBar: _buildBottomNavigationBar(),
floatingActionButton: _buildFloatingActionButton(), floatingActionButton: _buildFloatingActionButton(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
@ -161,6 +162,15 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
} }
} }
Widget _buildBodyWithFriendsOverlay() {
return Stack(
children: [
_buildBody(),
if (_showFriendsOverlay) const Positioned.fill(child: FriendsScreen()),
],
);
}
Widget _buildFeed() { Widget _buildFeed() {
final filteredActivities = _getFilteredActivities(); final filteredActivities = _getFilteredActivities();
return RefreshIndicator( return RefreshIndicator(
@ -413,7 +423,7 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
} }
Widget _buildNavItem(int index, IconData icon, String label) { Widget _buildNavItem(int index, IconData icon, String label) {
final isSelected = _selectedIndex == index; final isSelected = index == 1 ? _showFriendsOverlay : _selectedIndex == index;
return Expanded( return Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () => _onItemTapped(index), onTap: () => _onItemTapped(index),

View File

@ -4,6 +4,7 @@ import 'services_screen.dart';
import 'ai_chat_screen.dart'; import 'ai_chat_screen.dart';
import 'messages_screen.dart'; import 'messages_screen.dart';
import 'profile_screen.dart'; import 'profile_screen.dart';
import 'create_activity_screen.dart';
class MainScreen extends StatefulWidget { class MainScreen extends StatefulWidget {
const MainScreen({super.key}); const MainScreen({super.key});
@ -26,6 +27,8 @@ class _MainScreenState extends State<MainScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: IndexedStack(index: _currentIndex, children: _screens), body: IndexedStack(index: _currentIndex, children: _screens),
floatingActionButton: _buildGlobalFab(),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex, currentIndex: _currentIndex,
onTap: (i) => setState(() => _currentIndex = i), onTap: (i) => setState(() => _currentIndex = i),
@ -39,4 +42,23 @@ class _MainScreenState extends State<MainScreen> {
), ),
); );
} }
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,
);
}
} }

Binary file not shown.