0

Following is the class, I want to make it singleton, unable to use async await in _internal function.

class AppState {
  static final AppState _instance = AppState._internal();

  factory AppState() {
    return _instance;
  }

  late FirebaseApp app;
  late FirebaseDatabase appDb;

  void init() async {
    app = await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    appDb = FirebaseDatabase.instanceFor(
        app: app,
        databaseURL:
            "https://moddeell122-rtdb.asia-southeast1.firebasedatabase.app/");
  }

  AppState._internal() {
  //ADD AWAIT HERE
    init();
  }
}
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • You will need to use an `async` `static` method instead of a constructor, and your singleton will need to be a `Future` instead of an `AppState`. – jamesdlin Nov 05 '22 at 20:11
  • @jamesdlin can you post the code this as answer so i can mark it as well – Shan Khan Nov 05 '22 at 20:58

0 Answers0