![](/img/trans.png)
[英]How to save and load two variables in the same screen in Flutter/Dart?
[英]How to Specify Intended Variable When two Variables Have Same Name and Different Scope in Dart?
假設在 Dart (DartPad) 中我們有:
String a = "I am higher in the scope chain";
void main() {
String a = "I am lower in the scope chain, but I have the same name";
print(a);
}
是否有我們可以使用的關鍵字,以便它打印父 scope 中的變量,例如:
print(parent.a)
要么
print(this.a)
?
(那些不起作用)。
如果你的文件名是'some_dart_file.dart',你可以這樣做
import './some_dart_file.dart' as parent show a;
String a = "I am higher in the scope chain";
void main() {
String a = "I am lower in the scope chain, but I have the same name";
print(parent.a);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.