flutter 为什么我无法从www.example.com获取preparationstep的数据https://rapidapi.com/apidojo/api/yummly2,它显示为null

egdjgwm8  于 2023-02-25  发布在  Flutter
关注(0)|答案(1)|浏览(114)

请帮助我解决null的问题,为什么我不能从https://rapidapi.com/apidojo/api/yummly2中获取preparationstep的数据,它在flutter中显示null请帮助我
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}';
#   }
# }
# ```
#
9rygscc1

9rygscc11#

编译器清楚地表明您接收到的Null不是String的子类型,这意味着您将值声明为String,但不知何故,您接收到的null是因为将null检查简单地传递到模型类中:变更类型
final String name-----〉final String ? name
对于每个值也是如此
更多信息请查看:https://flutterigniter.com/checking-null-aware-operators-dart/

相关问题