我的 Flutter 应用程序需要一个不显示的全局变量(因此没有 UI 更改),但每次更改时都需要运行一个函数。我一直在浏览教程等,但它们的用途似乎都比我需要的要复杂得多,我更喜欢使用仍然被认为是“良好实践”的最简单的方法。
大致上我正在尝试做的事情:
//inside main.dart
int anInteger = 0;
int changeInteger (int i) = {
anInteger = i;
callThisFunction();
}
//inside another file
changeInteger(9);
Run Code Online (Sandbox Code Playgroud)