Flutter - 无法在初始化程序中访问实例成员 'remoteConfig'
Flutter - The instance member 'remoteConfig' can't be accessed in an initializer
我正在尝试在 List
中调用 remoteConfig
字符串
class HomeModel {
final RemoteConfig remoteConfig; //HomeModel() is called in Home() and fetches the param from there
HomeModel({this.remoteConfig});
List taskList = [
{
'title': 'Hello',
'url': remoteConfig.getString(''),
},
];
}
但是,它显示错误 -
The instance member 'remoteConfig' can't be accessed in an initializer
将 taskList
的初始化移动到 initState()
。
List taskList;
@override
void initState() {
taskList = [
{
'title': 'Hello',
'url': remoteConfig.getString(''),
},
];
super.initState();
}
我正在尝试在 List
remoteConfig
字符串
class HomeModel {
final RemoteConfig remoteConfig; //HomeModel() is called in Home() and fetches the param from there
HomeModel({this.remoteConfig});
List taskList = [
{
'title': 'Hello',
'url': remoteConfig.getString(''),
},
];
}
但是,它显示错误 -
The instance member 'remoteConfig' can't be accessed in an initializer
将 taskList
的初始化移动到 initState()
。
List taskList;
@override
void initState() {
taskList = [
{
'title': 'Hello',
'url': remoteConfig.getString(''),
},
];
super.initState();
}