【发布时间】:2020-06-10 19:30:54
【问题描述】:
我正在尝试以这样一种方式创建一个 UI,即一行中的按钮数量会根据可用信息而变化。更具体地说,总会有一个FlatButton 链接到外部页面,但如果还提供了下载链接,那么行中还会有第二个FlatButton。
在当前存在的网站上,我们为 one button 和 two buttons 工作,但我无法让一个按钮水平扩展以填充可用空间。
目前,我将FlatButtons 添加到List<Widget> 变量中,我将其作为子项传递给一行。我已经尝试使用Flex -> Expanded、SizedBox.expand、CrossAxisAlignment.stretch 以及到目前为止我在此站点上找到的每个解决方案来扩展它,但是我尝试过的每个解决方案都导致forced infinite width 或unbounded width 或non-zero flex but incoming width constraints are unbounded.
这是我目前在 build 方法中的代码:
List<Widget> fullTextDownloadBtns = new List();
if (this.fullArticleUrl != null && this.fullArticleUrl.isNotEmpty) {
fullTextDownloadBtns.add(
FlatButton(
color: Color(0x66629c44),
onPressed: _openFullArticle,
child: Text(
"Full Article",
style: TextStyle(color: Color(0xff629c44)),
),
)
);
}
if (this.downloadUrl != null && this.downloadUrl.isNotEmpty) {
fullTextDownloadBtns.add(
FlatButton(
color: Color(0x664d69b1),
onPressed: _download,
child: Text(
"Download",
style: TextStyle(color: Color(0xff4d69b1)),
),
)
);
}
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff0096b0)
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ...related image, title
Container(
padding: EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: fullTextDownloadBtns,
),
), // Read full article & download PDF
// ... Authors, excerpt/description, like/share buttons, comments
],
)
),
);
【问题讨论】: