skip to Main Content

I have a problem when I fetch data using provider in Flutter.

I’ve tried changing it to NULL (UserBiodata?) without using LATE but the error occurs again in other parts.

Error

Here is the code I wrote:

class UserBiodataProfile with ChangeNotifier {
  late UserBiodata _userBiodata;
  UserBiodata get userBiodata => _userBiodata;

  set userBiodata(UserBiodata newUserBiodata) {
    _userBiodata = newUserBiodata;
    notifyListeners();
  }
}

I call the data here:

Text(
  userBiodataProvider.userBiodata.data.name,
  style: bold5,
),

How do I solve it?

2

Answers


  1. Try the following code:

    final UserBiodata userBiodata = UserBiodata(
      status: …,
      code: …,
      data: …,
    );
    

    Text(
      userBiodata.data.name,
      style: bold5,
    ),
    
    Login or Signup to reply.
  2. While loding the data is null.

    try this code

    class UserBiodataProfile with ChangeNotifier {
      UserBiodata? _userBiodata;
      UserBiodata? get userBiodata => _userBiodata;
    
      set userBiodata(UserBiodata? newUserBiodata) {
        _userBiodata = newUserBiodata;
        notifyListeners();
      }
    }
    

    Text(
    userBiodataProvider.userBiodata == null ?  "" : 
    userBiodataProvider.userBiodata.data.name,
    style: bold5,
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search