-1

Please help me to solve the problem of null why I can't fetch data of preparationstep from https://rapidapi.com/apidojo/api/yummly2 it shows null in flutter help me please

enter image description here

# **code**
# ```
# recipe.dart
# 
`# import 'dart:html';
# 
# class Recipe {
# final String name;
# final String images;
# final double rating;
# final String totalTime;
# final String preparationSteps;
# 
# Recipe({
# required this.name,
# required this.images,
# required this.rating,
# required this.totalTime,
# required this.preparationSteps,
#   });
# 
# factory Recipe.fromJson(dynamic json) {
# return Recipe(
# name: json['name'] as String,
# images: json['images'][0]['hostedLargeUrl'] as String,
# rating: json['rating'] as double,
# totalTime: json['totalTime'] as String,
# preparationSteps: json['preparationSteps'] as String,
#     );
#   }
# 
# static List<Recipe> recipesFromSnapshot(List snapshot) {
# return snapshot.map((data) {
# return Recipe.fromJson(data);
#     }).toList();
#   }
# 
#   @override
# String toString() {
# return 'Recipe {name: $name, image: $images, rating: $rating, totalTime: $totalTime, preparationSteps: $preparationSteps}';
#   }
# }
# ```
# 
Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

The compiler clearly said that you are receiving Null is not a subtype of String which mean you declare your value to be String but somehow you are Receiving null for that simple pass null check into your model class: change type

final String name -----> final String ? name

The same goes for every value

for more info check this:https://flutterigniter.com/checking-null-aware-operators-dart/

Mashood .H
  • 926
  • 6
  • 16