【问题标题】:Push trailing widget to bottom of Flutter Navigation Rail将尾随小部件推送到 Flutter Navigation Rail 的底部
【发布时间】:2020-11-05 10:25:22
【问题描述】:

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

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

// other navrail properties....

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

【问题讨论】:

  • 不幸的是你不能!一种方法是复制 NavigationRail 代码并调整尾部以使其展开。
  • 哇,这很痛苦。那时我可能会考虑提交我的第一个功能请求!
  • 我试过了,直到我意识到这是不可能的。你找到解决办法了吗?

标签: flutter


【解决方案1】:

我找到了解决方案(或变通方法):

NavigationRailPositioned 小部件放入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),
        ),
      ],
    ),
  );

希望尽快修复!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-04
    • 2021-08-26
    • 1970-01-01
    • 2019-01-19
    • 2021-08-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多