skip to Main Content

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.

2

Answers


  1. 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);
    
    Login or Signup to reply.
  2. Try below code.

    setState(() {
      globals.globalDeviceVersion = null;
    });
    print(globals.globalDeviceVersion);
    

    and without state:

    globals.globalDeviceVersion = null;
    print(globals.globalDeviceVersion);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search