5

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.

chetan mahajan
  • 349
  • 4
  • 15

3 Answers3

2

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)

Matthew Rideout
  • 7,330
  • 2
  • 42
  • 61
1

Sometimes it may happen due to uninitialized Map Fields on set operation, So initialze it,

Map<String> jsonResult;

To

Map<String> jsonResult={};
insaneray
  • 75
  • 1
  • 11
0

I was getting this error relating to the file_picker library on Flutter web.

The null reference is in the FilePickerResult result object. result.files.single.path This returns null on Flutter web, but not on any other platform for some reason.

If this is the case, you may need to change something like the following to resolve the issue:

FilePickerResult uploadfile = File(result.files.single.path);

to:

Uint8List uploadfile = result.files.single.bytes;

I found the solution from this answer, so all credit to him:

https://stackoverflow.com/a/65435068/5654210

Thanks!

Webkraft Studios
  • 492
  • 5
  • 18