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.
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?
CodePudding user response:
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,
),
CodePudding user response:
Try the following code:
final UserBiodata userBiodata = UserBiodata(
status: …,
code: …,
data: …,
);
Text(
userBiodata.data.name,
style: bold5,
),