flutter - 颤振长列表给出 NoSuchMethodError
问题描述
我正在构建一个应用程序,其中我在 TabBarView 中使用了一个长列表。但是当它启动这个列表时,它会给出以下错误;
NoSuchMethodError:在 null 上调用了 getter 'length'。
接收方:空
尝试调用:长度
另见:https ://flutter.dev/docs/testing/errors
下面是我的 main.dart;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp(
contacts : List<String>.generate(10000, (i) {return "Contact $i";}),
));
class MyApp extends StatelessWidget {
final List<String> contacts;
const MyApp({Key key, this.contacts}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('Contacts'),
bottom: TabBar(tabs: [
Tab(icon: Icon(Icons.smartphone)),
Tab(icon: Icon(Icons.face))
]),
),
body: TabBarView(
children: [
ListView.builder(
itemCount: contacts.length,
itemBuilder: (context, index){
return ListTile(
title: Text('Contact ${contacts[index]}')
);
},
),
Center(child: Text('hello text')),
]
),
),
),
);
}
}
解决方案
推荐阅读
- monads - 如何在 Idris 中使用 ST 来获得 ReaderT r Maybe a 的功能?
- python - 使用 Python SQLAlchemy 将 JSON 发布到数据库
- centos - Centos iptables 显示规则但没有安装服务
- node.js - 路由处理程序中的函数
- c++ - 如何有效地对满足给定谓词的向量中的所有项目进行操作?
- android - 如何在响应解码 jwt 中获取价值并保存共享首选项
- java - 重构遗留代码——接口实现java——使用非接口方法
- c# - 从计划任务生成文本
- php - php - simpleXML 试图了解什么正在使用内存
- rabbitmq - 许多消费者手动排队。RabbitMQ 中的一个消费者到多个队列