颤振 | ExpansionTile 属性 "children" 在展开时引发底部溢出问题
Flutter | ExpansionTile property "children" throws a Bottom Overflowed issue on expanding
我正在构建一个从 Firestore 中获取的项目列表,这些项目包装在 ListView.builder()
中的 ExpansionTile
中。数据被正确获取。那里没有问题。我可以看到这些项目的列表。
问题出在 Tile 扩展上,我需要显示一些 ListTile
。但是在展开时,它给我一个 Bottom Overflowed by X pixels
。
为了解决这个问题,我尝试将它包装在 ListView
中,但它抛出异常 -
Another exception was thrown: NoSuchMethodError: The
method '<=' was called on null.
运气不好。
我正在编写这样的代码 -
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class NewExpansionPanel extends StatefulWidget {
@override
_NewExpansionPanelState createState() => _NewExpansionPanelState();
}
class _NewExpansionPanelState extends State<NewExpansionPanel> {
Widget getListOfTexts(){
return ListView(
children: <Text>[
Text('one'),
Text('two'),
Text('three'),
],
);
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection(*someCollection*).snapshots(),
builder: (context, snapshot) {
if(!snapshot.hasData) return const Text("Loading.....");
return ListView.builder(
itemExtent: 80.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
final DocumentSnapshot document = snapshot.data.documents[index];
return new ExpansionTile(
children: [
getListOfTexts()
],
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
document['something'] ?? ' ',
),
Text(document['title'] ?? '<No title retrieved>'),
],
),
onExpansionChanged: (bool isExpanded) {
// put some code here in future
},
);
}
);
}
);
}
}
您是否尝试在没有 ListView 的情况下直接使用 ExpansionTile 子文本?
是这样的...
...//
return new ExpansionTile(
children: [
Text('one'),
Text('two'),
Text('three'),
],
...
或者对文本使用 ListTile..
return new ExpansionTile(
children: [
ListTile(title: Text('one'),),
ListTile(title: Text('Two'),),
ListTile(title: Text('Three'),),
],
这很尴尬。我只需要删除 ListView.builder
上的 itemExtent: 80.0
属性。这导致了 Bottom Overflowed
问题。
我正在构建一个从 Firestore 中获取的项目列表,这些项目包装在 ListView.builder()
中的 ExpansionTile
中。数据被正确获取。那里没有问题。我可以看到这些项目的列表。
问题出在 Tile 扩展上,我需要显示一些 ListTile
。但是在展开时,它给我一个 Bottom Overflowed by X pixels
。
为了解决这个问题,我尝试将它包装在 ListView
中,但它抛出异常 -
Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
运气不好。
我正在编写这样的代码 -
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class NewExpansionPanel extends StatefulWidget {
@override
_NewExpansionPanelState createState() => _NewExpansionPanelState();
}
class _NewExpansionPanelState extends State<NewExpansionPanel> {
Widget getListOfTexts(){
return ListView(
children: <Text>[
Text('one'),
Text('two'),
Text('three'),
],
);
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection(*someCollection*).snapshots(),
builder: (context, snapshot) {
if(!snapshot.hasData) return const Text("Loading.....");
return ListView.builder(
itemExtent: 80.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
final DocumentSnapshot document = snapshot.data.documents[index];
return new ExpansionTile(
children: [
getListOfTexts()
],
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
document['something'] ?? ' ',
),
Text(document['title'] ?? '<No title retrieved>'),
],
),
onExpansionChanged: (bool isExpanded) {
// put some code here in future
},
);
}
);
}
);
}
}
您是否尝试在没有 ListView 的情况下直接使用 ExpansionTile 子文本? 是这样的...
...//
return new ExpansionTile(
children: [
Text('one'),
Text('two'),
Text('three'),
],
...
或者对文本使用 ListTile..
return new ExpansionTile(
children: [
ListTile(title: Text('one'),),
ListTile(title: Text('Two'),),
ListTile(title: Text('Three'),),
],
这很尴尬。我只需要删除 ListView.builder
上的 itemExtent: 80.0
属性。这导致了 Bottom Overflowed
问题。