How to send user out of the application - To a specific directory path

Viewed 447

I have a specific path where user files are exported under the following path:
e.g : /storage/emulated/0/Android/data/com.example.app_name/files
However the problem is not how generate the path but how to do this redirection (open the folder where the file is stored). I've tried to use the plugin url_launcher but apparently it doesn't work.I tried to launch this path as url:
code example :

FlatButton(
    onPressed: () async{
        // _localPath returns /storage/emulated/0/Android/data/com.example.app_name/files 
        final path = await _localPath;
        if (await canLaunch(path)) {
            await launch(path);
        } else {
            throw 'Could not launch $path';
          }
        },
    child: Text('Navigate to App storage Folder'),
      ),

The user exported the data as csv file and he want to use that file.
The expected result : user will be redirected to the path (folder files) and exit the Flutter application. PS : I'm targeting only Android Platform.

1 Answers

I seem to have found a solution for your question with a package called open_file. You can simply point to the path you want to open and it will ask the OS for the app you want to use to handle files or use what is set as your default.

Basic code example:

class OpenDirectoryPath extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: RaisedButton(
        child: Text('Open path'),
        onPressed: () {
          _openPath('/storage/emulated/0/Download/');
        },
      ),
    );
  }

  void _openPath(String path) async {
    OpenFile.open(path);
  }
}

(tested in Android)

Related