Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Save file visible to the user

In a Flutter project I create a pdf document. I can save the document in the path of the app. But the user has no access to it. Alternatively, how can I save the file to another folder where the user sees it?

import 'package:path_provider/path_provider.dart';
  Future<void> savePdfDocument() async {
    final PdfCreater generatedPdf = PdfCreater(document);
    final List<int> generatedPdfDocument = generatedPdf.buildPdf();

    final String dir = (await getApplicationDocumentsDirectory()).path;
    final String path = '$dir/example.pdf';
    final File file = File(path);
    file.writeAsBytesSync(generatedPdfDocument);
  }
like image 853
Markus Bach Avatar asked Dec 03 '19 09:12

Markus Bach


Video Answer


1 Answers

This works like a charm

String documentsPath = '/storage/emulated/0/Documents/';
if (Platform.isIOS) {
  Directory path = await getApplicationDocumentsDirectory();
  documentsPath = path.path;
}

Also don't forgot to add this to pubspec path_provider: 2.0.1

like image 154
JayLord Abueva Avatar answered Oct 07 '22 17:10

JayLord Abueva