python - 在dart/Flutter中是否有与python的global关键字等效的功能?

标签 python flutter dart

在python中,我们具有global关键字,该关键字使我们可以在函数中使用全局变量,如下所示:

test = "this is a test"

def change_test():
    global test
    test = "I've changed it"

change_test()
print(test) # should print (I've changed it) to the console.

在dart / flutter中相当于什么。我没有发现任何类似的东西。

最佳答案

在Flutter中称为static变量。例:

void main(){
 print(Circle.pi);
}

class Circle{
 static double pi = 3.1415;
}

这是一段解释Dart中静态变量的视频:https://www.youtube.com/watch?v=gmEVGdswpO0

关于python - 在dart/Flutter中是否有与python的global关键字等效的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60896790/

相关文章:

dart - 如何捕获计时器函数调用中抛出的错误?

python - Python 中的打印问题

python - 使用 futures.ProcessPoolExecutor 但不使用带有 PRAW 包装器的 futures.ThreadPoolExecutor 时的递归最大错误

python - 矩阵转置

flutter - 谷歌通过 flutter 中的webview登录canva的问题

Flutter:使用带有卡住和 json_serializable 的 Map

python - 如何在 Python 中连接一个字符串

android - 如何在Dart中组合循环结果

flutter - 小部件构建期间如何在抖动中导航?

flutter - 如何将Future <int>传递给父类(super class)