Issue
I’m trying to call API in the web app is show this error and Android and iOS Working fine. I don’t understand why happening.I’m using retrofit and dio to call api’s.
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:web_app/utils/constants.dart';
class ServiceError {
static BuildContext context;
ServiceError(BuildContext context) {
context = context;
}
void getError(final res) {
print("MyError" + res.toString()); // I got null value and this working fine in android and iOS. only i get problem in web app
final jsonResponse = jsonDecode(res.toString());
ApiError apiError = ApiError.fromJson(jsonResponse);
print("MyError" + apiError.status);
print("MyCode" + apiError.message);
if (apiError.responseCode == 500) {
Constants.toast(apiError.message);
} else {
Constants.toast(apiError.message);
}
}
}
I got this error
TypeError: Cannot read property 'Symbol(dartx._get)' of null
at new service_errors.ApiError.fromJson (http://localhost:44059/packages/web_app/service_errors/service_errors.dart.lib.js:103:36)
at service_errors.ServiceError.new.getError (http://localhost:44059/packages/web_app/service_errors/service_errors.dart.lib.js:23:22)
at http://localhost:44059/packages/web_app/forgot_password/reset_password.dart.lib.js:6485:58
at _RootZone.runUnary (http://localhost:44059/dart_sdk.js:37533:58)
at _FutureListener.catchError.handleError (http://localhost:44059/dart_sdk.js:32521:48)
at handleError (http://localhost:44059/dart_sdk.js:33070:51)
at Function._propagateToListeners (http://localhost:44059/dart_sdk.js:33096:17)
at _Future.new.[_completeError] (http://localhost:44059/dart_sdk.js:32943:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:44059/dart_sdk.js:32981:31)
at Object._microtaskLoop (http://localhost:44059/dart_sdk.js:37794:13)
at _startMicrotaskLoop (http://localhost:44059/dart_sdk.js:37800:13)
at http://localhost:44059/dart_sdk.js:33309:9
Not realy sure what is actually causing the issue, hope you can help.
Thank you so mush.
Solution
CORS Related Issue
My Flutter Web app communicates with an Azure Function. The iOS and Android versions worked fine, but I was getting the property 'Symbol(dartx._get)' of null
error above when attempting to execute a graphql query against the azure function in flutter web. Chetan’s CORS hint in the comment above gave me a clue.
This Stack Overflow Q&A resolved the issues I have having on production and localhost. CORS with Azure function from localhost (not CLI)
Answered By – Matthew Rideout
Answer Checked By – Mary Flores (FlutterFixes Volunteer)