'Flutter issue on save PDF file to android file manager app

Hello I am facing issue on save PDF file at android file manager app. Works good in iOS. Android error log :

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Creation failed, path = '/data/user/0/com.tippbucket.app/app_flutter/abc.pdf' (OS Error: Not a directory, errno = 20).

Here is the code:

final status = await Permission.storage.request();

if (status.isGranted) {

    var dir = Platform.isAndroid ? await getApplicationDocumentsDirectory() //FOR ANDROID          
        :
        await getApplicationDocumentsDirectory();

    final String localPath = 'TIPP_BUCKET_${DateTime.now().toIso8601String()}';

    var savedPath = p.join(dir.path, "abc.pdf");
    var result = await WebcontentConverter.webUriToPdf(uri: url, savedPath: savedPath, format: PaperFormat.a4, margins: PdfMargins.px(top: 20, bottom: 20, right: 20, left: 20), );

    WebcontentConverter.logger.info(result ?? '');
    new Directory(result).create(recursive: true).then((Directory directory) async {
        String path = directory.path;
        File f;
        f = await File(savedPath).create();
        f.writeAsStringSync(path);
    });
}

Please help me on resolve flutter issue.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source