I am very new to flutter and dart and trying to use singleton instance for global state(?). which is company info that gets from backend server. When flutter app starts, send request to the server and get a response and build a singleton instance based on the response. So I created class
class Company {
static final Company _instance = new Company._internal();
factory Company() {
return _instance;
}
@protected
String name;
@protected
String intro;
String get companyName => name;
String get companyIntro => intro;
void setCompany(String name, String intro) {
name = name;
intro = intro;
}
Company._internal();
}
in main.dart
// companyResult is the response from server
final String companyName = companyResult["name"];
final String companyIntro = companyResult["intro"];
// create singleton instance
var company = Company();
// set company info
company.setCompany(companyName, companyIntro);
// cheking
print(company.companyName)
prints null
What am I doing wrong?