【发布时间】:2018-04-02 20:02:25
【问题描述】:
我正在尝试使用SliverPadding 在SliverFixedExtentList 下添加填充以填充屏幕,并在屏幕底部添加Text.rich 小部件。计算列表的高度相当容易,因为我正在设置范围。但我也应该牢记Text.rich 小部件的高度。
我不确定如何在构建时计算Text.rich 小部件的高度,这可能吗?如果没有,有什么更好的方法?
我一直在使用以下代码:
Widget build(BuildContext context) {
double maxNonScrollableListSize = (MediaQuery.of(context).size.height - listPadding.bottom - listPadding.top - bottomFooterPadding.bottom - fontSize - 2);
double totalChildHeight = childCount * itemExtent;
double footerPadding = maxNonScrollableListSize > totalChildHeight ? maxNonScrollableListSize - totalChildHeight : 5.0;
return new Scaffold(
body: new Container(
color: new Color.fromRGBO(50, 120, 176, 1.0),
child: new CustomScrollView(
slivers: <Widget>[
new SliverPadding(
padding: listPadding,
sliver: new SliverFixedExtentList(
itemExtent: itemExtent,
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
return new Card(
child: new Container(
child: new Center(child: new Text("Card $index")),
),
);
},
childCount: childCount,
),
),
),
new SliverPadding(
padding: new EdgeInsets.only(bottom: footerPadding),
),
new SliverToBoxAdapter(
child: new Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Container(child: new Text("ok", style: new TextStyle(fontSize: fontSize),))
],
),
),
new SliverPadding(
padding: bottomFooterPadding,
),
],
)
),
);
}
【问题讨论】: