The argument type ‘String?’ can’t be assigned to the parameter type ‘String’.
Container(
width: 54,
height: 54,
decoration:BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(
user.profilePhotoUrl,
),
),
),
),
please helpmee
2
Answers
Dart offers null safety to the users.
For example when we declare
String? name;
default value ofname
isnull
and can be changed.But we cannot declare
String name;
you have to give value while declaring likeString name = 'Funny Name';
ensuring that value ofname
can never be null.Here use
!
mark after the variable to tell the compiler that value ofuser.profilePhotoUrl
is not null likeuser.profilePhotoUrl!
My suggestion is to use
String
intead ofString?
in that case you don’t need to use!
we should always handle null value case first. Here if in case a the value of "profilePhotoUrl" is equal to null then we have handle it with this default link which is after ?? ‘any other link’.
Here is an example :
In below example i haven’t provided any value to profilePhotoUrl and declared it as nullable & so when it execute it will get null but as we have handle it already using null operator.
??
Called also null operator. This operator returns expression on its left, except if it is null, and if so, it returns right expression:
What are ??, ??=, ?., …? in Dart?
https://jelenaaa.medium.com/what-are-in-dart-df1f11706dd6