-1

I'm working with an API to create a movie app with flutter. I'm using the Bloc library for state management but I have an issue displaying the json response on my UI because flutter somehow thinks the list is empty even though the json list prints in the console and its not empty.

I've searched for answers online and some people suggest and I've tried every solution but it hasn't worked. I'll appreciate if anyone can help check the code and point out wgere my mistake is. The code has gotten a little complicated and I don't think I can just paste the code here.

https://github.com/darmhey/movie_app

The most logical solution I've come across is that I'm referencing the list before it is fetched from the API but it still seems I don't know how I can solve it. I have something like if list.empty return a, else return b. it returns a always

1 Answers1

0

Issue related to parsing logic. JSON has property results but in your model you are parsing result. As the result, your output is empty.

Rename result field to results in the MovieResponse

@JsonSerializable(explicitToJson: true)
class MovieResponse {
  final int page;
  final List<Movie>? results;

  MovieResponse({required this.page, this.results});

  factory MovieResponse.fromJson(Map<String, dynamic> json) =>
      _$MovieResponseFromJson(json);
  Map<String, dynamic> toJson() => _$MovieResponseToJson(this);
}

Regenerate your code

flutter pub run build_runner build --delete-conflicting-outputs
powerman23rus
  • 1,297
  • 1
  • 9
  • 17