【发布时间】:2020-09-14 02:37:12
【问题描述】:
Screenshot of what I am looking for
如何在 Flutter 中实现这个侧边导航栏(左)?如果我没记错的话,有一个小部件,但我在任何地方都找不到这个名字。
【问题讨论】:
标签: flutter dart material-design
Screenshot of what I am looking for
如何在 Flutter 中实现这个侧边导航栏(左)?如果我没记错的话,有一个小部件,但我在任何地方都找不到这个名字。
【问题讨论】:
标签: flutter dart material-design
这称为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'),
),
]
},
【讨论】:
您正在搜索的小部件名为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'),
),
)
],
),
);
}
【讨论】: