gpt4 book ai didi

flutter - Flutter Datatable-空容器会减慢加载时间

转载 作者:行者123 更新时间:2023-12-03 03:49:12 33 4
gpt4 key购买 nike

我正在构建一个应用程序,其中将家庭详细信息(分为3个部分)在同一页面上显示为3个不同的数据表。问题是在加载将显示3个数据表的页面之前,捕获了一个异常,此后页面将加载并正确显示3个数据表以及正确的数据。

════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building SecondPage(dirty, dependencies: [MediaQuery], state: _SecondPageState#eba94):
The method 'map' was called on null.
Receiver: null
Tried calling: map<DataRow>(Closure: (AdultDetails) => DataRow)

The relevant error-causing widget was
SecondPage
具有小部件SecondPage的代码:
 children:<Widget>[
Container(
height: 50,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: OutlineButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SecondPage(widget.familyRef)),
);
},
为了隐藏异常,我将空容器传递给每个数据表。
class SecondPage extends StatefulWidget {
//final String adultid;
final String familyRef;

SecondPage(this.familyRef);
@override
_SecondPageState createState() => _SecondPageState();
}
...
Container(
width: MediaQuery.of(context).size.width,
child: FittedBox(
child: DataTable(
headingRowHeight: 50,
dataRowHeight: 50,
//columnSpacing: 10,
dividerThickness: 1,
columns: [
DataColumn(
label: Text(
"First Name",
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
numeric: false,
tooltip: "",
),
DataColumn(
label: Center(
child: Text(
"Update",
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
)),
numeric: false,
tooltip: "",
),
],
rows: list1?.map(
(item) => DataRow(cells: [
DataCell(
Text(item.pensionerName.toString()),
),

DataCell(OutlineButton(
child: Text("Update"),
onPressed: () {
Route route = MaterialPageRoute(
builder: (context) => UpdateAdult(
widget.familyRef,
item.adultid,
));
Navigator.push(context, route);
},
))
]),
)?.toList() ?? [],
),
它为我工作-方法'map'在null上调用。错误屏幕没有出现,但是现在每个数据表需要大约3秒钟的时间加载。我该怎么做才能提高加载性能?您的帮助将不胜感激。

最佳答案

使用三元条件
例:

list1 == null ? Container() : list1?.map(
(item) => DataRow(cells: [
DataCell(
Text(item.pensionerName.toString()),
),

...

)?.toList() ?? [],
),

关于flutter - Flutter Datatable-空容器会减慢加载时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64316397/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com