skip to Main Content

Good day, I have been trying the below code:

class SearchMovieCard extends StatelessWidget {
  final MovieEntity movie;

  const SearchMovieCard({super.key, required this.movie});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).push(
          MaterialPageRoute(
            builder: (context) => MovieDetailScreen(
              movieDetailArguments: MovieDetailArguments(
                movie.id,
              ),
            ),
          ),
        );
      },
      child: Padding(
        padding: EdgeInsets.symmetric(
          horizontal: Sizes.dimen_16.w.toDouble(),
          vertical: Sizes.dimen_2.h.toDouble(),
        ),
        child: Row(
          children: [
            Padding(
              padding: EdgeInsets.all(
                Sizes.dimen_8.w.toDouble(),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(
                  Sizes.dimen_4.w.toDouble(),
                ),
                child: CachedNetworkImage(
                  imageUrl: '${ApiConstants.BASE_IMAGE_URL}${movie.posterPath}',
                  width: Sizes.dimen_80.w.toDouble(),
                ),
              ),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Text(
                    movie.title,
                    style: Theme.of(context).textTheme.subtitle1,
                  ),
                  Text(
                    movie.overview,
                    maxLines: 3,
                    overflow: TextOverflow.ellipsis,
                    style: Theme.of(context).textTheme.greyCaption,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

But in my code Text(movie.overview,), I get the error I wrote in the title. I would be very happy if you help me with the solution of the error.

I’ve tried looking online for articles with this error but it doesn’t fix the error at all. I also asked the same to ChatGPT and it still didn’t fix it.

Usually on the internet they say ?? "" type this code and it will be fixed. I tried but I keep getting the same error.

3

Answers


  1. Did you try to add double quote to both title and overview ?

    Text(
      movie.title ?? "",
      style: Theme.of(context).textTheme.subtitle1,
      ),
    Text(
      movie.overview ?? "",
      maxLines: 3,
      overflow: TextOverflow.ellipsis,
      style: Theme.of(context).textTheme.greyCaption,
    ),
    
    Login or Signup to reply.
  2. Add a null check operator (!) into your text variable.

    For Example:

    Text(
        movie!.title,
        style: Theme.of(context).textTheme.subtitle1,
        ),
    Text(
       movie!.overview,
       maxLines: 3,
       overflow: TextOverflow.ellipsis,
       style: Theme.of(context).textTheme.greyCaption,
       ),
    
    Login or Signup to reply.
  3. usually this happen if the value may be null so you need to fix if the value is null
    either use ! to make the movie nullable

    Text(movie!.overview
    maxLines: 3,
    overflow: TextOverflow.ellipsis,
    style: Theme.of(context).textTheme.greyCaption,
    )
    

    or use ?? if null then "" means blank

    Text(
    movie.overview ?? "",
    maxLines: 3,
    overflow: TextOverflow.ellipsis,
    style: Theme.of(context).textTheme.greyCaption,
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search