child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.category, //here )
I want to display the category where i call it from database but the Text fill occur an error. Please help me
CodePudding user response:
You defined category as a nullable String. That is of type String?. A Text widget requires it to be non-nullable, which is of type String. There's a couple of solutions:
Make the
categorynon-nullable. To do that changeString? categorytoString category. This might give other errors so it might not be possible for you to do.If you are sure it's never
nullat that place in the code write a!behind the variable name. LikeText(widget.category!). This will throw errors at runtime in case it is actuallynull.You could also provide a fallback value in case it's null, like
Text(widget.category ?? 'fallback'). This is probably the safest solution.
CodePudding user response:
This means, category is nullable. So you could write instead Text(widget.category ?? 'alt text') what provides some alt text if category is null.
CodePudding user response:
Change widget.category
to
widget?.category: "" 