[英]Why I got The relevant error-causing widget was: Scaffold?
Hello everyone I want to dispaly some informations inside scaffold but I got The relevant error-causing widget was: Scaffold.大家好,我想在脚手架内显示一些信息,但我得到了导致错误的相关小部件:脚手架。 Even when I remove it I still got errors:
即使我删除它,我仍然会收到错误消息:
this is the code:这是代码:
Widget build(BuildContext context) {
return Scaffold(
body: ExpansionTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.model.name,
overflow: TextOverflow.ellipsis,
),
Text(
widget.model.id.toString(),
style: Theme.of(context).textTheme.caption,
)
],
),
leading: SingleChildScrollView(
child: Column(
// children: [
// Text(widget.model.mtu.toString()),
children: <Widget>[
StreamBuilder(
stream: widget.model.mtu,
initialData: 0,
builder: (c, snapshot) => ListTile(
title: const Text('MTU Size'),
subtitle: Text('${snapshot.data} bytes'),
),
// ],
),
],
),
),
trailing: TextButton(
onPressed: () {
setState(() {
buttonText = 'Connecting...';
});
widget.viewModel.establishConnectAndEnableNotify(widget.model);
},
child: Text(
buttonText,
style: TextStyle(color: AppColors.blue),
).tr(),
)));
}
}
I would be very thankful if you can help me如果你能帮助我,我将不胜感激
The issue occurring because of using ListTile
, it is trying to get infinite width.由于使用
ListTile
而出现的问题,它试图获得无限宽度。 You can wrap it with SizedBox and provide width.您可以用 SizedBox 包装它并提供宽度。 Using
LayoutBuilder
on top level will be better to get the parent widget width.在顶层使用
LayoutBuilder
将更好地获取父窗口小部件的宽度。
return Scaffold(
body: LayoutBuilder(
builder: (_, constraints) => ExpansionTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[],
),
leading: SingleChildScrollView(
child: Column(
// children: [
// Text(widget.model.mtu.toString()),
children: <Widget>[
StreamBuilder(
// stream: "widget.model.mtu",
initialData: 0,
builder: (c, snapshot) => SizedBox(
width:
constraints.maxWidth * .2, //depend on you or hard-coded value
child: ListTile(
title: Text(' w ${constraints.maxWidth}'),
subtitle: Text('${snapshot.data} bytes'),
),
),
// ],
),
],
),
),
Also, I think you don't want to have SingleChildScrollView
on leading
, maybe you like to use it on children
另外,我认为你不想在
leading
上使用SingleChildScrollView
,也许你喜欢在children
身上使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.