title: How to download pdf file from firebase in IOS and Android download folder - Flutter
body: <p>Hello I am having a challenge on how to download files to my download folder both in IOS and Android please can anyone help me? The problem I am having is when I click the download the circularloadingindicator loads just fine and everything process to 100% and it shows that the download complete but I can't see the file in my download folder. I just find the fire.</p>
  <p>Here is my download snippet</p>
  <pre><code>import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
  import 'package:flutter/foundation.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter_app/models/book.dart';
  import 'package:hexcolor/hexcolor.dart';
  import 'dart:async';
  import 'dart:io';
  import 'package:dio/dio.dart';
  import 'package:path_provider/path_provider.dart';
  import 'package:ext_storage/ext_storage.dart';
  import 'package:permission_handler/permission_handler.dart';
  
  
  class DetailsPage extends StatefulWidget {
    final Book book;
  
    DetailsPage({Key key, @required this.book}) : super(key: key);
  
    @override
    _DetailsPageState createState() =&gt; _DetailsPageState(book);
  }
  
  class _DetailsPageState extends State&lt;DetailsPage&gt; {
    bool _isLoading = false;
    final Book book;
    bool downloading = false;
    var progressString = &quot;&quot;;
    _DetailsPageState(this.book);
  
  // Download start
  
    @override
    void initState() {
      super.initState();
      downloadFile();
    }
  
     //get storage permission
    void getPermission() async {
      print(&quot;getPermission&quot;);
      await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    }
  
    Future&lt;void&gt; downloadFile() async {
      Dio dio = Dio();
  
      try {
        var dir = await getApplicationDocumentsDirectory();
  
        Response response = await dio.download(book.url, &quot;${dir.path}/${book.title}.pdf&quot;,
            onReceiveProgress: (rec, total) {
          print(&quot;Rec: $rec , Total: $total&quot;);
  
          setState(() {
            downloading = true;
            progressString = ((rec / total) * 100).toStringAsFixed(0) + &quot;%&quot;;
          });
        });
  
      //write in download folder
      File file = File(dir.path);
      var raf = file.openSync(mode: FileMode.write);
      raf.writeFromSync(response.data);
      await raf.close();
  
      } catch (e) {
        print(e);
      }
  
      setState(() {
        downloading = false;
        progressString = &quot;Completed&quot;;
      });
      print(&quot;Download completed&quot;);
    }
  
    // Download end
    @override
    Widget build(BuildContext context) {
      //book Image
      final topLeft = Column(
        children: &lt;Widget&gt;[
          Padding(
            padding: EdgeInsets.all(16.0),
            child: Hero(
              tag: Text(book.title),
              child: Material(
                elevation: 15.0,
                shadowColor: Colors.green.shade900,
                child: Image(
                  image: NetworkImage(book.image),
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
          Text(
            '${book.page}',
            style: TextStyle(
              color: Colors.black38,
              fontSize: 12,
            ),
          )
        ],
      );
  
      //book details right
      final topRight =
          Column(crossAxisAlignment: CrossAxisAlignment.start, children: &lt;Widget&gt;[
        Padding(
          padding: EdgeInsets.only(top: 16.0),
          child: Text(book.title,
              style: TextStyle(
                color: Colors.black87,
                fontSize: 12.toDouble(),
              )),
        ),
        Padding(
          padding: EdgeInsets.only(top: 8.0),
          child: Text('Author: ${book.author}',
              style: TextStyle(
                color: Colors.black54,
                fontSize: 12,
              )),
        ),
        Padding(
          padding: EdgeInsets.only(top: 8.0),
          child: Text('Comment: ${book.comment}',
              style: TextStyle(
                color: Colors.black54,
                fontSize: 12,
              )),
        ),
        SizedBox(height: 32.0),
        Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: &lt;Widget&gt;[
          Material(
            borderRadius: BorderRadius.circular(20.0),
            shadowColor: Colors.blue.shade200,
            elevation: 5.0,
            child: _isLoading
                ? Center(child: CircularProgressIndicator())
                : MaterialButton(
                    onPressed: () async {
                      setState(() =&gt; _isLoading = true);
                      await PDFDocument.fromURL(&quot;${book.url}&quot;).then((val) {
                        return showDialog(
                            context: context,
                            builder: (context) {
                              return AlertDialog(
                                content: PDFViewer(
                                  document: val,
                                  enableSwipeNavigation: true,
                                  lazyLoad: false,
                                ),
                              );
                            });
                      });
                      setState(() =&gt; _isLoading = false);
                    },
                    minWidth: 70.0,
                    color: Colors.blue,
                    child: Text(
                      'Read Now',
                      style: TextStyle(color: Colors.white, fontSize: 14),
                    ),
                  ),
          ),
          downloading
              ? Center(child: CircularProgressIndicator())
              : Material(
                  borderRadius: BorderRadius.circular(20.0),
                  shadowColor: Colors.green.shade200,
                  elevation: 5.0,
                  child: MaterialButton(
                    onPressed: () async {},
                    minWidth: 70.0,
                    color: Colors.green,
                    child: Text(
                      'Download',
                      style: TextStyle(color: Colors.white, fontSize: 14),
                    ),
                  ),
                ),
        ]),
      ]);
  
      //top image and text combined
      final topContent = Container(
        padding: EdgeInsets.only(bottom: 16.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: &lt;Widget&gt;[
            Flexible(flex: 2, child: topLeft),
            Flexible(flex: 3, child: topRight),
          ],
        ),
      );
      Divider();
      //bottom description
      final bottomContent = Container(
        height: 220.0,
        child: SingleChildScrollView(
          padding: EdgeInsets.only(left: 20.0, bottom: 16.0),
          child: Text(
            book.description,
            style: TextStyle(fontSize: 13.0, height: 1.5),
          ),
        ),
      );
      return Scaffold(
        appBar: AppBar(
          elevation: .5,
          title: Text('Book Details'),
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
                colors: [
                  Hexcolor(&quot;#8DCCB1&quot;),
                  Hexcolor(&quot;#043e2a&quot;),
                ],
              ),
            ),
          ),
        ),
        body: Column(
          children: &lt;Widget&gt;[
            topContent,
            bottomContent,
            downloading
                ? Container(
                    height: 80.0,
                    width: 200.0,
                    child: Card(
                      color: Colors.white,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: &lt;Widget&gt;[
                          Text(
                            &quot;Downloading File: $progressString&quot;,
                            style: TextStyle(
                              color: Colors.green,
                            ),
                          )
                        ],
                      ),
                    ),
                  )
                : Container()
          ],
        ),
      );
    }
  }
  
  </code></pre>
  <p>in my pubspec.yaml here are the extensions:</p>
  <pre><code>dependencies:
    flutter:
      sdk: flutter
    hexcolor: ^1.0.4
    flutter_launcher_icons: &quot;^0.7.3&quot;
    firebase_core: ^0.5.0
    advance_pdf_viewer: ^1.2.0
    file_picker: ^2.0.6
    firebase_storage: ^4.0.1
    multi_media_picker: ^0.2.3
    cloud_firestore:
    firebase_auth:
    modal_progress_hud:
    pull_to_refresh: ^1.6.1
    flutter_downloader: ^1.4.4
    permission_handler: 4.4.0
    ext_storage: ^1.0.3
    random_pk: any
    dio: any
    path_provider: any
  </code></pre>
  <p>for the android I went to this file:</p>
  <pre><code>project&gt;android&gt;app&gt;src&gt;main&gt;AndroidManifest.xml
  </code></pre>
  <p>and I added</p>
  <pre><code> &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
  </code></pre>
  <p>Just before this tag   but I can't see anything working please can anyone help me on what to do?</p>