Reputation: 112
I use a global variable:
String? globalDeviceVersion;
And I set the variable when I connect via bluetooth device and it works good.
The issue is when I want to 'reset' the global value and I have tried:
setState(() {
globals.globalDeviceVersion == null;
});
print(globals.globalDeviceVersion);
and without state:
globals.globalDeviceVersion == null;
print(globals.globalDeviceVersion);
The print in both cases just prints the previous value and the global is not set to null.
Upvotes: 1
Views: 57
Reputation: 1285
Try below code.
setState(() {
globals.globalDeviceVersion = null;
});
print(globals.globalDeviceVersion);
and without state:
globals.globalDeviceVersion = null;
print(globals.globalDeviceVersion);
Upvotes: 3
Reputation: 344
I think the issue here is you are comparing the globals.globalDeviceVersion to null not changing the value the code would be
setState(() {
globals.globalDeviceVersion = null; //modify == to = only
});
print(globals.globalDeviceVersion);
Upvotes: 3