The argument type 'RequestOptions' can't be assigned to the parameter type 'Options'

Viewed 842

updating one of our dev environments and now going in circles with this issue. Has anyone seen it before that can offer some pointers? Many thanks

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode... Running Gradle task 'assembleDebug'... lib/RestClient/UserAllGameClient.g.dart:41:18: Error: The argument type 'RequestOptions' can't be assigned to the parameter type 'Options'.

  • 'RequestOptions' is from 'package:dio/src/options.dart' ('../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/dio-4.0.0/lib/src/options.dart').
  • 'Options' is from '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;
  }
}
2 Answers

You have to change RequestOptions to Options(Dio)

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