skip to Main Content

How can I get the project’s root folder in Flutter? Basically what is the equivalent of python’s os.path.dirname(os.path.abspath(__file__))?

2

Answers


  1. Im not sure what you mean but if you want app directory you can use this package

    path_provider

    import 'package:path_provider/path_provider.dart';
    
    Future<Directory> getAppDirectory() async {
      final directory = await getApplicationDocumentsDirectory();
      return directory;
    }
    
    Login or Signup to reply.
  2. you can use Directory.current to get your projects root directory. This is the directory where your pubspec.yaml is located. Checkout an example below.

    import 'dart:io';
     
    main() {
      Directory current = Directory.current;
    
      print(current);
      print(current.path);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search