0

As we know, there is a getApplicationDocumentsDirectory() function that returns a Future<Directory> in package path_provider. But now I want to init a static variable through it:

class Settings {
  static final Directory rootDirectory = /*The documents directory*/;
}

I can't use await here. How can I do?

lhgzbxhz
  • 25
  • 2

1 Answers1

0

use like this pathprovider depend on each platform code you need use await method .Dont initialize provider (if you can reduce ) on every class or widget .initialize this main method and use everywhere

    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
//use like this pathprovider depend on each platform code you need use await method .Dont initialize pathproviderclass on every class or widget .initialize this main method and use everywhere
      var pa = await getApplicationDocumentsDirectory();
      settings.rootDirectory = pa;
      runApp(MyApp());
    }
    
    class settings {
      static late final Directory? rootDirectory;
    }
lava
  • 2,903
  • 2
  • 21
  • 19