flutter - flutter 全局变量

标签 flutter dart

flutter应用程序中的全局变量不能在 Release模式下工作?我的flutter应用程序在 Debug模式下可以正常工作,但在 Release模式下却不工作。我是否必须将全局变量包装在类中。
我的全局变量

void main() => runApp(MyApp(
));


int _character=1 ;
bool language=true;
String str = '';
double _strokeSize=0;
double w;
double h;
double f=28;
// double offset=kToolbarHeight;

Color pickerColor = Color(0xff443a49);
Color currentColor = Color(0xff443a49);

Color strokepickerColor = Color(0xff443a49);
Color strokechangeColor = Color(0xff443a49);

ScreenshotController screenshotController = ScreenshotController(); 

//rest of the code

}
PS:我是新手

最佳答案

格式是

 class GlobalVariable {
   static const int character = 1;
   static const bool status = true;
 }
并且您应该使用static关键字,然后只有它才能保留值(value)。

关于flutter - flutter 全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62618634/

相关文章:

dart - flutter 垂直视口(viewport)无界高度错误

dart - Dart Analyzer无法在vscode中启动

flutter - 如何在 Dart 中从两个不同的列表创建公共(public)元素的列表?

flutter - dart null 安全中的 "!"和 "?"运算符之间有什么区别?

visual-studio-code - Visual Studio Code : dart not found

Flutter:FCM 未处理异常:对空值使用空检查运算符

flutter - 我如何根据条件查看 FloatingActionButton

Flutter FutureBuilder 返回 Null 错误被触发

flutter - 如何在 Flutter 中以编程方式显示/隐藏小部件

class - 如何在Dart中将父类转换为子类