flutter 无法将参数类型“RequestOptions”分配给参数类型“Options”

5ktev3wc  于 2023-05-19  发布在  Flutter
关注(0)|答案(3)|浏览(336)

更新我们的开发环境之一,现在在这个问题上兜圈子。有没有人看过这本书,可以提供一些建议?非常感谢
正在调试模式下在sdk gphone 64 x86 64上启动lib/main.dart...正在运行Gradle任务“assembleDebug”... lib/RestClient/UserAllGameClient.g.dart:41:18:错误:无法将参数类型“RequestOptions”分配给参数类型“Options”。

  • 'RequestOptions'来自'package:dio/src/options.dart'('../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/dio-4.0.0/lib/src/options.dart')。
  • 'Options'来自'package:dio/src/options.dart'('../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/dio-4.0.0/lib/src/options.dart')。options:RequestOptions(^
Future<List<dynamic>> getUserAllGames() async {
    const _extra = <String, dynamic>{};
    SharedPreferences pref = await SharedPreferences.getInstance();
    Map<String, String> headers = {
      HttpHeaders.contentTypeHeader: "application/json",
      HttpHeaders.authorizationHeader: "Bearer ${pref.getString("token")}",
    };
    
    final response = await _dio.get('game/all',
        options: RequestOptions(
            method: 'GET',
            headers: headers,
            extra: _extra,
            baseUrl: baseUrl)
    );
    print(response);
    return response.data;
  }
}
7xzttuei

7xzttuei1#

您必须将RequestOptions更改为Options(Dio)

options: Options(
  method: 'GET',
  headers: headers,
  ...
)
pwuypxnk

pwuypxnk2#

dart-dio有一个新的“null-safety”生成器:“dart-dio-next”https://openapi-generator.tech/docs/generators/dart-dio-next
好像很管用!

qgzx9mmu

qgzx9mmu3#

我们必须继续使用Options。查看API document了解更多信息。以下是修改后的请求:

final response = await _dio.get('game/all',
    options: Options(
        method: 'GET',
        headers: headers,
        extra: _extra,
        baseUrl: baseUrl)
);

相关问题