fix: 修复底部导航栏被覆盖和FAB消失问题
This commit is contained in:
parent
f4c5369792
commit
c87a6756db
@ -13,6 +13,7 @@ class ActivityListScreen extends StatefulWidget {
|
||||
|
||||
class _ActivityListScreenState extends State<ActivityListScreen> {
|
||||
int _selectedIndex = 0;
|
||||
bool _showFriendsOverlay = false;
|
||||
final _feedKey = GlobalKey<RefreshIndicatorState>();
|
||||
String? _selectedTime;
|
||||
|
||||
@ -83,10 +84,6 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
|
||||
}
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
if (index == 0 && _selectedIndex == 0) {
|
||||
_feedKey.currentState?.show();
|
||||
return;
|
||||
}
|
||||
if (index == 2) {
|
||||
// 中间按钮 - 跳转到发布页面
|
||||
Navigator.push(
|
||||
@ -95,24 +92,26 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const FriendsScreen()),
|
||||
);
|
||||
setState(() {
|
||||
_showFriendsOverlay = !_showFriendsOverlay;
|
||||
if (_showFriendsOverlay) {
|
||||
_selectedIndex = 0;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (index == 3 || index == 4) {
|
||||
if (_selectedIndex != index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
if (index == 0 && _selectedIndex == 0 && !_showFriendsOverlay) {
|
||||
_feedKey.currentState?.show();
|
||||
return;
|
||||
}
|
||||
if (_selectedIndex != index) {
|
||||
|
||||
if (_selectedIndex != index || _showFriendsOverlay) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
_showFriendsOverlay = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -123,27 +122,29 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
|
||||
if (_selectedIndex == 3 || _selectedIndex == 4) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFFF8F0),
|
||||
body: _buildBody(),
|
||||
body: _buildBodyWithFriendsOverlay(),
|
||||
bottomNavigationBar: _buildBottomNavigationBar(),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFFF8F0),
|
||||
appBar: AppBar(
|
||||
title: Text('伴享', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.search),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.notifications_none),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _buildBody(),
|
||||
appBar: _showFriendsOverlay
|
||||
? null
|
||||
: AppBar(
|
||||
title: Text('伴享', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.search),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.notifications_none),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _buildBodyWithFriendsOverlay(),
|
||||
bottomNavigationBar: _buildBottomNavigationBar(),
|
||||
floatingActionButton: _buildFloatingActionButton(),
|
||||
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() {
|
||||
final filteredActivities = _getFilteredActivities();
|
||||
return RefreshIndicator(
|
||||
@ -413,7 +423,7 @@ class _ActivityListScreenState extends State<ActivityListScreen> {
|
||||
}
|
||||
|
||||
Widget _buildNavItem(int index, IconData icon, String label) {
|
||||
final isSelected = _selectedIndex == index;
|
||||
final isSelected = index == 1 ? _showFriendsOverlay : _selectedIndex == index;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => _onItemTapped(index),
|
||||
|
||||
@ -4,6 +4,7 @@ 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});
|
||||
@ -26,6 +27,8 @@ class _MainScreenState extends State<MainScreen> {
|
||||
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),
|
||||
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
releases/banxiang-v1.2.0-bugfix.apk
Normal file
BIN
releases/banxiang-v1.2.0-bugfix.apk
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user