skip to Main Content

Error:

E/flutter (28049): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ‘package:object_mapper/src/mappable.dart’: Failed assertion: line 8 pos 12: ‘constructor != null’: RegistrationResponse is not defined in Reflection.factories
E/flutter (28049): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (28049): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (28049): #2 new Mappable (package:object_mapper/src/mappable.dart:8:12)
E/flutter (28049): #3 Mapper.toObject (package:object_mapper/src/mapper.dart:22:20)
E/flutter (28049): #4 DioClient.userRegistration (package:chavara/src/features/registration/service/registration_service.dart:20:45)
E/flutter (28049):
E/flutter (28049):
I/ViewRootImpl@219a9d3MainActivity: ViewPostIme pointer 0
I/ViewRootImpl@219a9d3MainActivity: ViewPostIme pointer 1

code:

    RegistrationResponse? user;

    try {
      Response userData =await WebUtil.createDio().post('/User',
      data:requestData);
      if (kDebugMode) {
        print('User Info: ${userData.data}');
      }
      user = Mapper.fromJson(userData.data).toObject<RegistrationResponse>();
    } on DioError catch (e) { }

2

Answers


  1. Chosen as BEST ANSWER
    Mappable.factories = {
          RegistrationResponse: () => RegistrationResponse(),
          Relation: () => Relation()
        };
    
    After adding this code in class, the code is working fine...
    

  2. List users =
    userData.map((userData.data) => Mapper.fromJson(data)).toList();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search