【发布时间】:2020-05-19 00:06:49
【问题描述】:
我有一段代码——有效!所以,不要寻求调试帮助。
我已经学习了三天,而且大部分时间都是积极的,但有时很难找到我正在尝试做的事情的工作代码示例。所以,大量的试验和错误。我最好的建议是将每个小部件的背景颜色设置为粗体(黄色、绿色、蓝色),以帮助解决设计/布局问题。
但是,我读了很多关于如何实现这样的东西:从 API 检索 json 数据,遍历它以使用 Future 创建一个动态的小部件列表。我这个时候的例子是纯flutter web。
问题是 - 许多网站也建议使用 List Builder,而在我的一生中,我无法让它工作。它一直溢出浏览器的底部,我找不到任何扩展它的方法。我使用了“for Model in List”循环,效果很好。
所以,我的问题是 - 如果我给你工作代码,你能提出更好的方法/实现吗?
Widget build(BuildContext context) {
return FutureBuilder<List<Menurender>>(
future: fetchMenu(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.none &&
snapshot.hasData == null) {
//print('project snapshot data is: ${projectSnap.data}');
return Container();
}
return Container(
width: MediaQuery.of(context).size.width,
//color: Colors.yellow,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * .80,
child: SingleChildScrollView(
child: Column(children: [
for (Menurender menu in snapshot.data)
Column(children: <Widget>[
Row(
children: <Widget>[
//SizedBox(width: 60),
Text(
'${menu.weekDayFull}',
style: TextStyle(
color: Color(0xff444444),
fontSize: 32,
letterSpacing: 2,
fontWeight: FontWeight.w600,
fontFamily: 'Fira Sans'),
),
],
),
Row(
children: <Widget>[
//SizedBox(width: 60),
Column(
children: <Widget>[
Text(
'${menu.dayOfMonth} ${menu.monthFull}',
style: TextStyle(
color: Color(0xff333333),
fontSize: 14,
fontWeight: FontWeight.w400,
fontFamily: 'Fira Sans'),
),
],
),
Expanded(
child: Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.fromLTRB(10.0, 0, 0, 0),
child: Container(
decoration: BoxDecoration(
//color: Colors.red,
border: Border(
bottom: BorderSide(
color: Color(0xff4A4A4A4A)),
)),
),
),
],
))
],
)
])
])),
),
],
),
);
});
}
实际工作的代码在这里,因此您可以看到我要完成的工作: 我的测试正在进行中: https://flavorboxstorage.z23.web.core.windows.net/#/
实际的公司 wordpress 网站: https://www.flavorboxsaigon.com/
【问题讨论】:
-
我的回答对你有用吗?
-
我仍在努力找出问题所在。
-
我遇到了错误
-
抛出了另一个异常:A RenderFlex 在右侧溢出了 98464 像素。引发了另一个异常:垂直视口被赋予了无限的高度。抛出了另一个异常:断言失败:org-dartlang-app:///packages/flutter/src/rendering/box.dart:1694:12 抛出了另一个异常:断言失败:org-dartlang-app:///packages /flutter/src/rendering/box.dart:1694:12 另一个异常抛出:断言失败:org-dartlang-app:///packages/flutter/src/rendering/box.dart:1694:12
-
我想出了无限的高度。 renderflex 溢出也是我的 for 循环中的一个错误。所以现在解决断言失败错误
标签: flutter dart flutter-web