Home > Enterprise >  null check operator used on a null value in flutter 3.0
null check operator used on a null value in flutter 3.0

Time:06-16

enter image description here

 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

  1. use errorBuilder in Image.network
  2. or change to like _featuredNews.title ?? '' to handle
  3. or receive the variables by 'required' variables . . .
  • Related