I am writing a program that uses HTTP to get a list of themes from a server, and when transforming the data from JSON I am getting this error.
TypeError: map[$_get] is not a function
packages/outlook/src/provider/response.dart 28:19 fromHTTP
packages/outlook/src/provider/outlook.impl.dart 74:7 <fn>
dart-sdk/lib/async/zone.dart 1653:54 runUnary
dart-sdk/lib/async/future_impl.dart 147:18 handleValue
dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn>
here is the method of getting the themes:
Future<OtlResponse<List<OutlookTheme>>> getThemes() {
return http
.post(serverDomain,
body: jsonEncode({'method': RequestMethods.getThemes.name,}))
.then((http.Response resp) {
Map<String, dynamic> body = jsonDecode(resp.body);
OtlResponse<List<OutlookTheme>> response =
OtlResponse<List<OutlookTheme>>.fromHTTP(
map: body,
data: List.from(body['themes'])
.map(( themeMap) => OutlookTheme.fromMap(Map.from(themeMap)))
.toList());
return response;
});
}
After decoding the response I am transforming it into and OtlResponse using this factory as shown here:
factory OtlResponse.fromHTTP({required Map<String, dynamic> map, required T data}) {
return OtlResponse<T>(
success: map['success'] as bool,
data: data,
context: map['context'] as String,
statusCode: map['statusCode'] as int,
methodId: (map['method'] as String).toEnum(RequestMethods.values),
);
}
According to the log , the error is coming from the fromHTTP() factory and where am calling it in the getThemes method. I tried using Map.from() after decoding and its not working. What can I do to fix this? any help would be much appreciated!
Well after stopping main run process and running it, it's now working.