get error in return userList![index]
List<UserListModal?>? userList = [];
itemCount: userList!.length,
itemBuilder: (_, index) {
return UserListView(user:userList![index]);
}))),```
2
Answers
Done it's front and back both two sides null safety
My SDK Version is Flutter 3.7.0-1.4
In your business logic, is it possible that userList can have null elements? Like:- userList = [null, null, UserListModal, null,]
If not, then please change the declaration to this:-
Explanation: Since you are assigning an empty list this this variable, userList cannot be null. So you can change the List<UserListModal?>? to List<UserListModal?>. And if you are not adding any null elements to this list, you can remove the remaining "?" i.e. change List<UserListModal?> to List.
I think you should read up on null safety in detail.
And using "final" makes sure that userModal cannot be re-assigned. This is a best practice for operating with lists.