[英]How can I access a variable from another file in dart
I am trying to access a variable called _country
from another file in dart, but an error occured: The getter '_country' isn't defined for the type 'CurrentCountry'.
我试图从 dart 中的另一个文件访问名为_country
的变量,但发生错误: The getter '_country' isn't defined for the type 'CurrentCountry'.
Here's the code where the variable I want to access is(in another file):这是我要访问的变量所在的代码(在另一个文件中):
class CurrentCountry {
static String _country = 'All';
}
And here's the code where I want to access the variable:这是我要访问变量的代码:
Future<Map<String, dynamic>> fetchWorldData() async {
Response activeResponse = await get(Uri.parse(
'https://disease.sh/v3/covid-19/countries/${CurrentCountry._country}'));
return json.decode(activeResponse.body);
}
If you can help me, I will be very grateful.如果你能帮助我,我将不胜感激。
You should remove the underscore of the variable.您应该删除变量的下划线。
If an identifier starts with an underscore (_), it's private to its library如果标识符以下划线 (_) 开头,则它对其库是私有的
Reference here: Dart language Important concepts参考这里:Dart语言重要概念
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.