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/