checkCompatibilityMapped method

Future<CompatibilityApiResult> checkCompatibilityMapped({
  1. required String path,
  2. required String appVersion,
  3. String queryParamKey = 'version',
})

Returns the result of api call to check the version, mapped into Equatable classes

path is the URL the endpoint that returns the response for GET request

appVersion is the app version string, for example '1.0.0'

queryParamKey is the query parameter name, default is 'version'

CompatibilityApiResult can be of types CompatibleAPIResult,WarningAPIResult or IncompatibleAPIResult

Implementation

Future<CompatibilityApiResult> checkCompatibilityMapped({
  required String path,
  required String appVersion,
  String queryParamKey = 'version',
}) async {
  final result = await get<Map<String, dynamic>>(path,
      queryParameters: {queryParamKey: appVersion});

  if (result.data!['status'] == Results.compatible) {
    return CompatibleAPIResult.fromJson(result.data!);
  }
  if (result.data!['status'] == Results.warning) {
    return WarningAPIResult.fromJson(result.data!);
  }

  return IncompatibleAPIResult.fromJson(result.data!);
}