【问题标题】:Flutter Side Navigation Bar widgetFlutter 侧边导航栏小部件
【发布时间】:2020-09-14 02:37:12
【问题描述】:

Screenshot of what I am looking for

如何在 Flutter 中实现这个侧边导航栏(左)?如果我没记错的话,有一个小部件,但我在任何地方都找不到这个名字。

【问题讨论】:

    标签: flutter dart material-design


    【解决方案1】:

    这称为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'),
        ),
      ]
      },
    

    【讨论】:

    • 非常感谢。也谢谢你的例子。
    【解决方案2】:

    您正在搜索的小部件名为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'),
              ),
            )
          ],
        ),
      );
    }
    

    【讨论】:

    • 非常感谢。这个名字完全跳过了我的脑海。也感谢您的使用案例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 2014-07-03
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多