I have a simple webpage that I would like to refresh every few minutes, defined by the user. So, for that I thought of using a global variable to store the value of how often the page should be refreshed. Unfortunately, it seems that after the page refreshes, all of the variable values are lost/restarted for some reason.
I tried using different kinds of imports, the singleton pattern, service pattern, a simple static variable inside a "Globals" class but nothing seems to work.
My current, relevant code for the global class is this:
class Globals {
static final Globals _instance = Globals._internal();
factory Globals() => _instance;
Globals._internal() {
_GLOBAL_REFRESH_MINUTES = 0;
}
int? _GLOBAL_REFRESH_MINUTES;
int get REFRESH_MINUTES => _GLOBAL_REFRESH_MINUTES!;
set REFRESH_MINUTES(int value) => _GLOBAL_REFRESH_MINUTES = value;
}
import 'package:myproject/common/globals.dart';
Globals _globals = Globals();
if (_globals.REFRESH_MINUTES > 0) {
new Timer.periodic(Duration(minutes: _globals.REFRESH_MINUTES),
(Timer t) => html.window.location.reload());
}