尝试使用here代码创建列表,但无法解决语法错误
class _ContactListItem extends ListView {
_ContactListItem(Contact contact) :
super(
title : new Text(contact.fullName),
subtitle: new Text(contact.email),
leading: new CircleAvatar(child: new Text(contact.fullName[0]))
);
}
错误是“未定义命名参数'标题'。”字幕和领导也存在同样的错误(我假设修复一个可以解决所有问题)。完全是新的扑动和飞镖所以任何反馈都是受欢迎的。
答案 0 :(得分:1)
您的_ContactListItem
来自错误的小部件。
您从ListView
延长,但您应该从ListItem
答案 1 :(得分:0)
这篇文章似乎过时了。您应该查看ListView docs上提供的示例代码。
答案 2 :(得分:0)
解决方案是扩展ListTile而不是ListView。我还必须更改ContactList类以使其运行。我现在拥有的是
class _ContactListItem extends ListTile {
_ContactListItem(Contact contact) :
super(
title : new Text(contact.fullName),
subtitle: new Text(contact.email),
leading: new CircleAvatar(child: new Text(contact.fullName[0]))
);
}
根据this post
中的构造函数错误更改了ContactList类class ContactList extends StatelessWidget {
final List<Contact> _contacts;
ContactList(this._contacts);
@override
Widget build(BuildContext context) {
return new ListView(
//type: MaterialListType.twoLine,
padding: new EdgeInsets.symmetric(vertical: 8.0),
children: _buildContactList()
);
}
List<_ContactListItem> _buildContactList() {
return _contacts.map((contact) => new _ContactListItem(contact))
.toList();
}
}
答案 3 :(得分:0)
我删除了提取的flutter sdk文件夹并解压缩并重新创建新项目有助于解决所有错误。希望它也对您有用
答案 4 :(得分:0)
Android Studio解决方案:文件>使高速缓存无效/重新启动