首页 文章

Flutter - 未定义命名的参数

提问于
浏览
0

尝试使用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]))
  );

}

错误是“未定义命名参数' Headers ' . ”字幕和领导也存在相同的错误(我假设修复一个可以解决所有问题) . 完全是新的扑动和飞镖所以任何反馈都是受欢迎的 .

4 回答

  • 0

    这篇文章似乎过时了 . 您应该查看ListView docs上提供的示例代码 .

  • 0

    您的 _ContactListItem 从错误的小部件扩展而来 . 你从_713536扩展,但你应该从 ListItem 延伸

  • 1

    解决方案是扩展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]))
      );
    
    }
    

    ContactList类根据this post中的构造函数错误进行更改

    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();
    }
    
    }
    
  • 0

    我删除了提取的flutter sdk文件夹并将其解压缩并重新创建新项目帮助解决了所有错误 . 希望它对你有用

相关问题