logo

该视频仅会员有权观看

立即开通课程「Flutter 移动端应用开发实践」权限。

¥
199
/ 年

点按底部导航栏项目切换当前活动项目

In the status class of an app file, we declare a property representing the current item of the bottom navigation bar, named current_app_bottom_navigation, initialized with a value of zero to set the first navigation item as active by default. We also define a function named onTapBottomNavigationBarItem which takes an int parameter called index representing the index of the current item. Within this function, the setState method provided by Flutter is called to update the app's state by setting current_app_bottom_navigation to the value of index. This state change triggers a rebuild of the app's interface. In the widget for the bottom navigation bar, currentIndex parameter is set using the current_app_bottom_navigation value, and the onTap is configured to call onTapBottomNavigationBarItem. Activating an item in the emulator triggers setState which updates the active state index and induces a rebuild, switching the tapped item to an active state.