【问题标题】:Get Container take the remaining space of the screen below the HeaderGet Container 占用 Header 下方屏幕的剩余空间
【发布时间】:2020-08-26 08:25:24
【问题描述】:

我的页面布局是这样的:

return new Scaffold(
  appBar: _getAppBarWidget(_currentIndex),
  body: return CustomScrollView(slivers: [
          SliverPersistentHeader(
            delegate: ProfileBar(expandedHeight: 200),
            pinned: true,
          ),
          SliverToBoxAdapter(
            child: ProfileView()
          ),
      ]);,
  bottomNavigationBar: BottomBar(),
);

我希望我的 ProfileView 占据整个屏幕尺寸。

ProfileView() 看起来像这样:

return Container(
  color: Colors.green;
  child: RaisedButton(
    child: const Text('Something'),
    textColor: Colors.white,
    color: Colors.redAccent,
    onPressed: () {}
  )
);

但我无法从 ProfileView 中获取我的 Container 以获取剩余在 SliverPersistentHeader 下方的屏幕高度的其余部分。

我尝试了很多不同的方法,但都没有成功。 (例如,使用 Expended)有人对此有建议吗?

编辑:我唯一成功的就是硬编码。但这不是我想要的。

【问题讨论】:

  • 您是否尝试使用 SliverFillRemaining 而不是 SliverToBoxAdapter 包装 ProfileView?
  • @shubham 其实我试过这个但没有成功。但既然你提到了它,我又试了一次,我成功了。谢谢!我不知道这次我做了什么不同。
  • 很高兴它对您有所帮助。我会将其发布为答案。

标签: flutter flutter-layout flutter-sliver


【解决方案1】:

要解决此问题,您可以使用 SliverFillRemaining 代替 SliverToBoxAdapter

所以你的更新代码将是

return new Scaffold(
appBar: _getAppBarWidget(_currentIndex),
body: return CustomScrollView(slivers: [
      SliverPersistentHeader(
        delegate: ProfileBar(expandedHeight: 200),
        pinned: true,
      ),
      SliverFillRemaining(
        child: ProfileView()
      ),
  ]);,
bottomNavigationBar: BottomBar(),
);

【讨论】:

    猜你喜欢
    • 2020-10-11
    • 2013-02-22
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    相关资源
    最近更新 更多