RenderBox 未布局:导致错误的相关小部件是 ExpansionTile
RenderBox was not laid out : The relevant error-causing widget was ExpansionTile
我创建了一个 ExpansionTile
小部件并在展开时使用 ListView.Builder
显示搜索文本字段和图书列表,但它向我发送了此错误
RenderBox was not laid out: RenderRepaintBoundary#6b9d7 NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1929 pos 12: 'hasSize'
The relevant error-causing widget was
ExpansionTile
这是代码
return SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
color: Color(int.parse(bodycolor)),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(children: [
ExpansionTile(
leading: Icon(Icons.info_rounded,
color: HexColor("#5344ed")),
title: Text(
"Select Staff",
style: GoogleFonts.montserrat(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: HexColor("#5344ed")),
),
children: [
buildSearch(),
ListView.builder(
shrinkWrap: true,
itemCount: books.length,
itemBuilder: (context, index) {
final book = books[index];
return ListTile(
title: Text(book.title),
subtitle: Text(book.author),
);
},
)
]),
])),
),
更新:
我编辑我的代码,结果是这个输出。
如果有人知道怎么做,请帮忙。
您只需将 SafeArea 包装在 Material
小部件中
试试下面的代码希望对你有帮助
您的列表 ->
List<String> data = [
"Counter No 1",
"Counter No 2",
"Counter No 3",
"Counter No 4",
];
你的小工具->
SingleChildScrollView(
child: Column(
children: [
// your other widget
buildSearch(),
ExpansionTile(
leading: Icon(
Icons.info_rounded,
),
title: Text(
"Select Staff",
),
children: [
ListView.builder(
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(data[index]),
subtitle: Text('Your Data'),
);
},
),
],
),
],
),
),
点击和其他小部件之前的结果屏幕->
点击后的结果屏幕->
你也可以在这里参考我对 ExpansionPanel
的回答
您需要将 SafeArea
包装在 Material
小部件中
我创建了一个 ExpansionTile
小部件并在展开时使用 ListView.Builder
显示搜索文本字段和图书列表,但它向我发送了此错误
RenderBox was not laid out: RenderRepaintBoundary#6b9d7 NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1929 pos 12: 'hasSize'
The relevant error-causing widget was
ExpansionTile
这是代码
return SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
color: Color(int.parse(bodycolor)),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(children: [
ExpansionTile(
leading: Icon(Icons.info_rounded,
color: HexColor("#5344ed")),
title: Text(
"Select Staff",
style: GoogleFonts.montserrat(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: HexColor("#5344ed")),
),
children: [
buildSearch(),
ListView.builder(
shrinkWrap: true,
itemCount: books.length,
itemBuilder: (context, index) {
final book = books[index];
return ListTile(
title: Text(book.title),
subtitle: Text(book.author),
);
},
)
]),
])),
),
更新:
我编辑我的代码,结果是这个输出。
如果有人知道怎么做,请帮忙。
您只需将 SafeArea 包装在 Material
小部件中
试试下面的代码希望对你有帮助
您的列表 ->
List<String> data = [
"Counter No 1",
"Counter No 2",
"Counter No 3",
"Counter No 4",
];
你的小工具->
SingleChildScrollView(
child: Column(
children: [
// your other widget
buildSearch(),
ExpansionTile(
leading: Icon(
Icons.info_rounded,
),
title: Text(
"Select Staff",
),
children: [
ListView.builder(
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(data[index]),
subtitle: Text('Your Data'),
);
},
),
],
),
],
),
),
点击和其他小部件之前的结果屏幕->
点击后的结果屏幕->
你也可以在这里参考我对 ExpansionPanel
的回答您需要将 SafeArea
包装在 Material
小部件中