小编Jer*_*ler的帖子

有没有办法在 SliverAppBar 的底部小部件中实现动态高度

SliverAppBar有一个属性bottom,它必须有preferredSize。

现在我让它返回恒定值:

  ...
  new SliverAppBar(
    expandedHeight: _kFlexibleSpaceMaxHeight,
    flexibleSpace: new FlexibleSpaceBar(.....)
    ...                   
    bottom: new BottomBar(...), // has to have preferredSize
  ),
  ...

class BottomBar extends StatelessWidget implements PreferredSizeWidget {
    ...
    @override
      Size get preferredSize {
        return new Size.fromHeight(my_constant_height_value);
      }

    ...
    }
Run Code Online (Sandbox Code Playgroud)

我想在这个底部小部件中放置一个文本,但我不知道其中的文本有多长。

如何实现底部小部件的动态高度?

有没有办法在布局之前测量小部件的高度?

编辑2018年4月25日

最终,我遵循蒂博的指示并得到了以下结果:

// 'as rendering' to avoid conflict with 'package:intl/intl.dart'
import 'package:flutter/rendering.dart' as rendering; 

...

// this is the function that returns the height of a Text widget
// given the text
double getHeight(String text, BuildContext context, …
Run Code Online (Sandbox Code Playgroud)

layout appbar flutter bottombar flutter-sliver

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

appbar ×1

bottombar ×1

flutter ×1

flutter-sliver ×1

layout ×1