将尾随小部件推到 Flutter Navigation Rail 的底部

Mat*_*att 8 flutter flutter-layout

如何将 Flutter Navigation Rail 中的尾随 widget 推到导轨底部?我认为这就像用扩展小部件包装尾随小部件一样简单,但我收到了通常的颤动需要绘制错误消息。

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

// other navrail properties....

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

Ric*_*ira 14

这并不难,使用 Expanded 和 Align 小部件:

NavigationRail(
  selectedIndex: _selectedIndex,
  destinations: _destinations,
  trailing: Expanded(
    child: Align(
      alignment: Alignment.bottomCenter,
      child: Padding(
        padding: const EdgeInsets.only(bottom: 8.0),
        child: IconButton(icon: const Icon(Icons.help), onPressed: (){}),
      ),
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

  • 作为副作用,“目的地”最终被推到了顶部...... (3认同)