首页 > 解决方案 > 尝试运行颤振应用程序时出现错误。参数的值不能为“null”

问题描述

这是我得到的错误,请告诉我该怎么做?

lib/models.dart:21:21: 错误:参数 'description' 的值不能为 'null',因为它的类型为
'String',但隐含的默认值为 'null'。尝试添加显式的非“null”默认值或“required”修饰符。WeatherInfo({this.description, this.icon});

lib/models.dart:21:39:错误:参数 'icon' 的值不能为 'null',因为它的类型为 'String',
但隐含的默认值是 'null'。尝试添加显式的非“null”默认值或“required”修饰符。WeatherInfo({this.description, this.icon});

lib/models.dart:33:25: 错误:参数“温度”的值不能为“空”,因为它的类型为
“双”,但隐含的默认值为“空”。尝试添加显式的非“null”默认值或“required”修饰符。温度信息({this.temperature});

lib/models.dart:50:25: 错误:参数“cityName”的值不能为“null”,因为它的类型为
“String”,但隐含的默认值为“null”。尝试添加显式的非“null”默认值或“required”修饰符。WeatherResponse({this.cityName, this.tempInfo, this.weatherInfo});

lib/models.dart:50:40: 错误:参数“tempInfo”的值不能为“null”,因为它的类型为
“TemperatureInfo”,但隐含的默认值为“null”。“TemperatureInfo”来自“package:flutterapp/models.dart”(“lib/models.dart”)。尝试添加显式的非“null”默认值或“required”修饰符。WeatherResponse({this.cityName, this.tempInfo, this.weatherInfo});

lib/models.dart:50:55: 错误:参数“weatherInfo”的值不能为“null”,因为它的类型为
“WeatherInfo”,但隐含的默认值为“null”。'WeatherInfo' 来自'package:flutterapp/models.dart' ('lib/models.dart')。尝试添加显式的非“null”默认值或“required”修饰符。WeatherResponse({this.cityName, this.tempInfo, this.weatherInfo});

lib/main.dart:19:19:错误:应该初始化字段“_response”,因为它的类型“WeatherResponse”不允许为空。'WeatherResponse' 来自'package:flutterapp/models.dart' ('lib/models.dart')。WeatherResponse_response;

标签: flutterdart

解决方案


This is the line with error.

  WeatherResponse _response;

必须初始化不可为空的实例字段“_response”。


推荐阅读