重构
This commit is contained in:
@@ -19,12 +19,14 @@ class MainNavigation extends StatefulWidget {
|
||||
|
||||
class _MainNavigationState extends State<MainNavigation> {
|
||||
int _currentIndex = 0;
|
||||
final GlobalKey<State<ProfilePage>> _profileKey =
|
||||
GlobalKey<State<ProfilePage>>();
|
||||
|
||||
final List<Widget> _pages = [
|
||||
late final List<Widget> _pages = [
|
||||
const HomePage(),
|
||||
const DiscoverPage(),
|
||||
const FavoritesPage(),
|
||||
const ProfilePage(),
|
||||
ProfilePage(key: _profileKey),
|
||||
];
|
||||
|
||||
final List<BottomNavigationBarItem> _bottomNavItems = [
|
||||
@@ -73,6 +75,13 @@ class _MainNavigationState extends State<MainNavigation> {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
// 切换到个人页面时刷新数据
|
||||
if (index == 3) {
|
||||
final profileState = _profileKey.currentState;
|
||||
if (profileState != null && profileState.mounted) {
|
||||
(profileState as dynamic).refreshData();
|
||||
}
|
||||
}
|
||||
},
|
||||
type: BottomNavigationBarType.fixed,
|
||||
selectedItemColor: AppConstants.primaryColor,
|
||||
|
||||
Reference in New Issue
Block a user