首页 > 解决方案 > 将尾随小部件推送到 Flutter Navigation Rail 的底部

问题描述

如何将 Flutter Navigation Rail 中的尾随小部件推到导轨底部?我认为这就像用 Expanded 小部件包装尾随小部件一样简单,但我得到了通常的颤动“需要油漆”错误消息。

如果我添加一个具有固定高度的 SizedBox 的第一个子项的 Column,然后添加我想要显示的小部件,我可以让它工作,但我需要“间隔器”来填充可用空间,而不是固定高度。这是 SizedBox 示例,它确实填充了 200px 的空间,但我如何让它填充可用空间?

// other navrail properties....

     trailing: Column(
        children: [
          SizedBox(
            height: 200,
          ),
          IconButton(icon: Icon(Icons.settings), onPressed: () {})
        ],
      ),

标签: flutter

解决方案


I found a solution (or workaround):

Put the NavigationRail and an Positioned widget in a Stack:

  Scaffold(
    body: Row(
      children: [
        Stack(
          children: [
            NavigationRail(
              selectedIndex: _selectedIndex,
              extended: Styling.isLargeScreen(context),
              destinations: _destinations
                  .map((d) => d.toNavigationDestination)
                  .toList(),
              onDestinationSelected: (index) => _onItemTapped(index),
            ),
            Positioned(
              bottom: 0,
              left: 0,
              right: 0,
              child: Container(
                color: Colors.amber,
                height: 100,
              ),
            )
          ],
        ),
        Expanded(
          child: _buildPage(_destinations.elementAt(_selectedIndex).key),
        ),
      ],
    ),
  );

Hopefully it gets fixed soon!


推荐阅读