我使用List.generate()从一个JSON对象中为每个类别创建一个表情符号列表。我有一个搜索栏,用于缩小搜索结果的范围。如果其中一个表情关键字包含搜索栏中的字符,则应该只显示该表情。
问题是SizedBox.shrink()并不像我希望的那样是空的。SizedBox.shrink()不是返回空部件的推荐方法吗?
谢谢!


Padding(
padding: EdgeInsets.only(left: 16, right: 16, top: 8),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
padding: EdgeInsets.only(left: 12, right: 12),
color: Colors.grey[200],
child: TextField(
onChanged: (change) {
setState(() {
searchTarget = change;
});
},
controller: searchController,
cursorColor: Colors.black,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Search for Icon..."),
),
),
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(
top: 16,
left: 16,
),
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: this.jsonData.keys.length,
itemBuilder: (context, index) {
return Column(
children: [
Padding(
padding: EdgeInsets.only(
bottom: 16, top: (index == 0) ? 0 : 16),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
this.jsonData.keys.toList()[index],
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
),
),
),
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 8,
children: List.generate(
this.jsonData[this.jsonData.keys.toList()[index]].length, (jndex) {
var emoji = this.jsonData[this.jsonData.keys.toList()[index]][jndex];
if (this.searchTarget.length > 0 || this.searchTarget != " "){
for (int i = 0; i < emoji['keywords'].length; i++){
if (emoji['keywords'][i].contains(this.searchTarget)){
return Text(
emoji['emoji'],
style: TextStyle(fontSize: 25),
);
}
}
}
return SizedBox.shrink();
}),
),
],
);
},
),
),
),发布于 2020-10-11 05:26:54
我解决了。我没有直接构建网格视图,而是创建了一个自己生成列表的方法。
https://stackoverflow.com/questions/64297517
复制相似问题