简体   繁体   English

_ $ CustomClass显示错误,如匿名闭包所定义,返回类型'Type'不是'CustomClass'。 `

[英]_$CustomClass shows error of `The return type 'Type' isn't a 'CustomClass', as defined by anonymous closure. `

I have add a new class TopicNew and run flutter pub run build_runner build --delete-conflicting-outputs in to a sample code from flutter_livestream_provider for learning. 我已经添加了一个新类TopicNew并运行flutter pub run build_runner build --delete-conflicting-outputsflutter_livestream_provider的示例代码中进行学习。

But I have no idea why my class shows error 但是我不知道为什么我的班级显示错误

import 'package:built_value/built_value.dart';

part 'topicNew.g.dart';

abstract class TopicNew implements Built<TopicNew, TopicNewBuilder> {
  int get id;
  String get name;
  TopicNew._();
  factory TopicNew([updates(TopicNewBuilder b)]) => _$TopicNew;  #<- show error here
}

在此处输入图片说明 在此处输入图片说明

This is a syntax error. 这是语法错误。

Instead of: 代替:

 => _$TopicNew;

do: 做:

 = _$TopicNew;

Factory constructors can be declared as 工厂构造函数可以声明为

factory Classname(int a) = OtherClass;

This syntax is a shorthand for 此语法是的简写

factory ClassName(int a) => OtherClass(a);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 固定错误:如何解决返回类型'StreamController<connectivitystatus> ' 不是匿名闭包错误所定义的 'Stream'</connectivitystatus> - Fixed-error: How to Solve The return type 'StreamController<ConnectivityStatus>' isn't a 'Stream', as defined by anonymous closure error 如何解决错误:Flutter中的“返回类型&#39;SliverStaggeredGrid&#39;不是由匿名闭包定义的&#39;Widget&#39;”? - How to fix error: “ The return type 'SliverStaggeredGrid' isn't a 'Widget', as defined by anonymous closure ” in Flutter? Flutter GetX 无法分配 Set<CustomClass> 到 RxSet<CustomClass> - Flutter GetX can't assign Set<CustomClass> to RxSet<CustomClass> 根据闭包上下文的要求,返回类型“Object”不是“Widget” - The return type 'Object' isn't a 'Widget', as required by the closure's context 根据闭包上下文的要求,返回类型“LoginPage”不是“void” - The return type 'LoginPage' isn't a 'void', as required by the closure's context 如何处理错误 " The return type 'List<card> ' 不是闭包上下文所要求的 'Widget'。”</card> - How to handle error " The return type 'List<Card>' isn't a 'Widget', as required by the closure's context." 返回类型“小部件?” 不是闭包上下文所要求的“小部件” - The return type 'Widget?' isn't a 'Widget', as required by the closure's context 根据闭包上下文的要求,返回类型“SignUpScreen”不是“void” - The return type 'SignUpScreen' isn't a 'void', as required by the closure's context 返回类型“字符串?” 不是闭包上下文所要求的“布尔” - The return type 'String?' isn't a 'bool', as required by the closure's context 根据闭包上下文的要求,返回类型“Person”不是“Widget” - The return type 'Person' isn't a 'Widget', as required by the closure's context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM