Basic Issue: Need to access Class throughout flutter application.
Requirements: Do not want this to be a stateful widget that i access.
Simply want a class that I can access by importing on other pages. I am persisting a user login with a set of variables, and I don't want to have to push this object from page to page.
Would like to simply access the class values
I was unable to find any good example for this using a singleton or other solutions that gave me what I was looking for.
import 'package:myApp/models/user.dart';
MyClass.Username = "testUser"; //Set the username
String currentUser = MyClass.Username; // Get the username
//Here is the top of the User class - is this creating a class that will
//only be defined once in the app, so if I set a value it will persist ?
class User {
static User _user = new User._internal();
factory User() {
return _user;
}
User._internal();
//More stuff
....}