Search code examples
androidflutterglobal-variablesshare

What is the best way to share variables with flutter?


I have these variables that I want to share it with another screen, what is the best way to share them beside Pushing them ?


Solution

  • You could try working with Singletons, store your variables in a singleton class and share them across screens.

    class YourClass {
      static YourClass _instance;
    
      YourClass._();
    
      static YourClass get instance => _instance = _instance ?? YourClass._();
    
      // Your instance variables that you want to share can go here
      var isVisible = false
    
    }