Flutter 侧导航栏小部件
Flutter Side Navigation Bar widget
Screenshot of what I am looking for
如何在Flutter中实现这个侧边导航栏(左)?如果我没记错的话,有一个小部件,但我在任何地方都找不到这个名字。
您正在搜索的小部件名为 NavigationRail
。
它被很好地记录为 part of the official Flutter API.
示例用法如下:
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: <Widget>[
NavigationRail(
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
});
},
labelType: NavigationRailLabelType.selected,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('First'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.book),
label: Text('Second'),
),
NavigationRailDestination(
icon: Icon(Icons.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Third'),
),
],
),
VerticalDivider(thickness: 1, width: 1),
// This is the main content.
Expanded(
child: Center(
child: Text('selectedIndex: $_selectedIndex'),
),
)
],
),
);
}
这叫做Navigation Rail
。您可以了解更多 here
用法:
child:NavigationRail(
selectedIndex:_currentIndex,
onDestinationSelected: (int index) {
setState(() {
// Change Index When Widget is Selected.
_currentIndex = index;
});
destinations:[
// You Navigation Rail Items/Destinations
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('Home'),
),
]
},
Screenshot of what I am looking for
如何在Flutter中实现这个侧边导航栏(左)?如果我没记错的话,有一个小部件,但我在任何地方都找不到这个名字。
您正在搜索的小部件名为 NavigationRail
。
它被很好地记录为 part of the official Flutter API.
示例用法如下:
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: <Widget>[
NavigationRail(
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
});
},
labelType: NavigationRailLabelType.selected,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('First'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.book),
label: Text('Second'),
),
NavigationRailDestination(
icon: Icon(Icons.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Third'),
),
],
),
VerticalDivider(thickness: 1, width: 1),
// This is the main content.
Expanded(
child: Center(
child: Text('selectedIndex: $_selectedIndex'),
),
)
],
),
);
}
这叫做Navigation Rail
。您可以了解更多 here
用法:
child:NavigationRail(
selectedIndex:_currentIndex,
onDestinationSelected: (int index) {
setState(() {
// Change Index When Widget is Selected.
_currentIndex = index;
});
destinations:[
// You Navigation Rail Items/Destinations
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('Home'),
),
]
},