I am a noob with Flutter/Dart/Firebase so I might be doing something obviously wrong:
class RemoteConfigService {
static final RemoteConfigService _singleton = RemoteConfigService._internal();
factory RemoteConfigService() {
return _singleton;
}
RemoteConfigService._internal();
final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.instance;
Future<void> initialize() async {
await remoteConfig.fetchAndActivate();
}
String get apiKey => remoteConfig.getString('apiKey');
}
Now I am trying to access apiKey in my main and it works as i see its value printed
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await RemoteConfigService().initialize();
String key = RemoteConfigService().apiKey;
print(key);
}
But when I try the same in view it doesn't work?
class _TestViewState extends State<TestView> {
....
Future<String> makeApiCall() async {
String apiKey = RemoteConfigService().apiKey; //coming back as empty
}
}
If it's already working in main() during init why not here. It's a singleton class. Any workarounds?
Tried a bunch of things including initializing RemoteConfigService() inside the makeApiCall() method and still shows up as empty.
Not sure what is up but I manually uninstalled the app on my phone before running "flutter run" and it worked this time.