参数类型不能分配给参数类型

时间:2019-07-26 03:46:34

标签: flutter dart

编辑:弗兰肯·弗兰克·赫洛回答,谢谢。

我正在尝试将结构发送到StatefulWidget,但是却收到错误消息
    “ code”:“ argument_type_not_assignable”,     “ message”:“无法将参数类型'RepData'分配给参数类型'RepScreen'。”,

错误行: _RepScreenState createState()=> _RepScreenState(产品);

结构是RepData,而我的StatefulWidget是RepScreen。

class RepScreen extends StatefulWidget {

  final RepData product;
  RepScreen(this.product);

  @override
  _RepScreenState createState() => _RepScreenState(product);
}

class _RepScreenState extends State<RepScreen> {

  final RepScreen product;
  _RepScreenState(this.product);

  @override
  Widget build(BuildContext context) {
    return Container(   
    );
  }
}

这是结构:

class RepData {

  String category;
  String id;
  String title;
  String text;
  List image;
  double long;
  double lat;
  String link;

  RepData.fromDocument(DocumentSnapshot snapshot){
    id = snapshot.documentID;
    title = snapshot.data['title'];
    text = snapshot.data['text'];
    image = snapshot.data['image'];
    long = snapshot.data['long'];
    lat = snapshot.data['lat'];
    link = snapshot.data['link'];
  }
 }

1 个答案:

答案 0 :(得分:0)

您的_RepScreenState的构造函数使用RepScreen,但是您在createState()中传递了RepData