颤振斩波器将生成的类用作响应类型

时间:2020-01-11 19:12:36

标签: flutter dart flutter-packages flutter-moor build-runner

在我的项目中,我使用的是Chopper(^ 3.0.1 + 1)和Moor(^ 2.2.0)软件包,但是我无法让它们协同工作。

在我的database.dart文件中,我创建了一个ActivityTypeTable类,该类扩展了Table,并使用@DataClassName(“ ActivityType”)进行了注释。正在运行的Flutter包pub build_runner build在database.g.dart文件中生成了一个ActivityType类。

在我的rest_client.dart类中,我有一个Chopper @Get方法,该方法应返回ActivityType对象的列表。我将其编写如下:

  @Get(path: '/Activity')
  Future<Response<List<ActivityType>>> getActivityTypes(@Query("token") String token, @Query("type") int type);

运行flutter包时,运行build_runner build时,似乎chopper_generator无法识别生成的ActivityType类。上面的实现在rest_client.chopper.dart文件中转换为以下代码:

  @override
  Future<Response<List>> getActivityTypes(String token, int type) {
    final $url = '/api/Activity';
    final $params = <String, dynamic>{'token': token, 'type': type};
    final $request = Request('GET', $url, client.baseUrl, parameters: $params);
    return client.send<List, List>($request);
  }

列表类型ActivityType被省略,因此假设它是动态类型的列表。这给了我以下错误:'_$RestClient.getActivityTypes' ('Future<Response<List<dynamic>>> Function(String, int)') isn't a valid override of 'RestClient.getActivityTypes' ('Future<Response<List<ActivityType>>> Function(String, int)').dart(invalid_override)

在我的pubspec.yaml中,我具有以下依赖性

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_core: ^0.4.3+1
  firebase_analytics: ^5.0.9

  flutter_svg: ^0.15.0
  chopper: ^3.0.1+1
  json_annotation: ^3.0.1
  get_it: ^1.0.3
  provider: ^4.0.1
  shared_preferences: ^0.5.6
  retrofit: ^1.0.1+1
  moor: ^2.2.0
  moor_ffi: ^0.3.1
  path_provider:
  path:

dev_dependencies:
  build_runner: 
  moor_generator: ^2.2.0
  json_serializable: ^3.2.0
  retrofit_generator: ^1.0.2+2
  chopper_generator: ^3.0.3
  flutter_test:
    sdk: flutter

描述的行为是故意的还是我应该在GitHub上针对chopper软件包提交问题?

0 个答案:

没有答案