Search code examples
flutterdartflutter-web

how to add condition if directory already exist in flutter


I am creating a directory now I want to add a condition if the directory already exists. This is my code

                    if(name == ''){  
                        print('empty controller');
                      }
                      else{
                        print('succcci');

                        var path = "storage/emulated/0/zip/$name";
                        new Directory(path).create();
                      }

Solution

  • You can use exists():

    var path = "storage/emulated/0/zip/$name";
    
    if(!await Directory(path).exists()){
       //need to create directory
       Directory(path).create();
    }