cannot assign value to object flutter

257 Views Asked by At

I want to assign values to an object "clientModel" but he always returning null


  ClientModel? clientModel ;
Future<void> getClientData(String email) async {
    emit(FidelityLoadingClientDataState());
        DioHelper.postData(url: GET_CLIENT,
            data: {
              "email":email
            }).then((value) {
             
              clientModel = ClientModel(status: true, message: "hello from the other side");

              emit(FidelityClientLoadingDataSuccess(clientModel));

        }).catchError((error)async{
          print(error.toString());

          emit(FidelityClientLoadingDataError(error.toString()));

        });
  }

}

even if assign manually value like this to the object :

clientModel = ClientModel(status: true, message: "hello from the other side");

the object return null

class Model :

class ClientModel {
  bool? status ;
  String? message ;
  ClientData? data;


  ClientModel({ this.status, this.message, this.data});

  factory ClientModel.fromJson(Map<String, dynamic> json) {
    return ClientModel(
      status: json['status'] ,
      message: json['message'] ,
      data: ClientData.fromJson(json['data']) ,
    );
  }



}

even i'm calling the method getClientData () in the start of the app but and I'm getting suucess state : 'FidelityClientLoadingDataSuccess' but the value of the object client model it's always null

0

There are 0 best solutions below