A brief understanding of the bottomNavigationBar property of the bottomNavigationBar property of the basic component Scaffold of Flutter

A brief understanding of the bottomNavigationBar property of the bottomNavigationBar property of the basic component Scaffold of Flutter

The bottomNavigationBar property is used to define the bottom navigation bar of the application. It is mainly composed of buttons and text. You can click the button to switch between different pages and display them in the bottom area of ​​the Scaffold.
The value of this property is the BottomNavigationBar type component. The BottomNavigationBar component includes the following table common properties.

property name Types of Function Description
currentIndex int Sets the current index value for the toggle button
fixedColor Color Set the color of the selected button, if not specified, use the system theme color
iconSize double Set button icon size
items List Set the bottom navigation bar button set, each item is a BottomNavigationBarItem, which consists of icon icon and title text attribute
onTap ValueChanged Set the callback event of pressing a button, you need to set the current index value according to the returned index value

Set the bottom navigation bar

/*设置底部导航栏*/
      bottomNavigationBar: BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(Icons.add_a_photo), title: Text('军机处')),
          BottomNavigationBarItem(
              icon: Icon(Icons.center_focus_strong), title: Text('血滴子')),
          BottomNavigationBarItem(
              icon: Icon(Icons.add_alarm_outlined), title: Text('大理寺'))
        ],
      ),

insert image description here

set click event

  /*设置单击事件*/
        onTap: (value){
    
    
          print(value);
        },

Test Click the three buttons below to output 0 1 2 respectively.
insert image description here
insert image description here
insert image description here
When the current index value is set to 1, select the second icon

 currentIndex: 1,

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_43336158/article/details/123487670