class News {
int? id;
String? title;
String? imageUrl;
}
return Container(
child: Center(
child: ListView(
children: [
Card(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.network(_featuredNews.imageUrl!),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
_featuredNews.title!,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
),
When I run this code Null check operator is used on a null value my flutter 3.0 please help me with what I do
CodePudding user response:
Flutter uses Dart language. Please refer to Dart - Null Aware Operators.
Add this
_featuredNews.title ?? ""
_featuredNews.imageUrl ?? ""
CodePudding user response:
Maybe _featuredNews.imageUrl! or _featuredNews.title! is the reason.
What about you try
- use
errorBuilder
in Image.network - or change to like
_featuredNews.title ?? ''
to handle - or receive the variables by 'required' variables . . .