title: FlutterDownloader works downloading pdf in android but fails on iOS
body: <p>I'm new to flutter/iOS.</p>
  <p>I'm using:</p>
  <p>Flutter 1.22.6 • channel stable • <a href="https://github.com/flutter/flutter.git" rel="nofollow noreferrer">https://github.com/flutter/flutter.git</a>
  Framework • revision 9b2d32b605 • 2021-01-22 14:36:39 -0800
  Engine • revision 2f0af37152
  Tools • Dart 2.10.5
  flutter_downloader: ^1.4.4</p>
  <p>I have to correct an application that I did not code I'm trying to understand it. It downloads a pdf file and open it, but is not working in iOS.</p>
  <p>All the configuration that I read in <a href="https://github.com/fluttercommunity/flutter_downloader" rel="nofollow noreferrer">https://github.com/fluttercommunity/flutter_downloader</a> is correct.</p>
  <p>Flutter doctor is OK.</p>
  <p>Below I show you parts of the code</p>
  <p><strong>main.dart</strong></p>
  <pre><code>final _prefs = SharedPreferences();
  
  void main() async {
    WidgetsFlutterBinding.ensureInitialized(); 
    final prefs = SharedPreferences();
    await prefs.initPrefs();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown
    ]);
    WidgetsFlutterBinding.ensureInitialized();
    await FlutterDownloader.initialize(debug: true);
    _prefs.uid = await getId();
    runApp(MyApp());
  }
  </code></pre>
  <p><strong>pages/registry/facture.dart</strong></p>
  <pre><code>List&lt;Widget&gt; _actionsCreateBar(BuildContext context) {
    return &lt;Widget&gt;[
      (document.id != null)
          ? IconButton(
              icon: Icon(EvaIcons.downloadOutline),
              onPressed: () async {
                _downloadAction(); // This method is executed when user press download icon
              },
              color: primaryColor,
              iconSize: 25,
            )
          : Container(),
    ];
  }
  
  void _downloadAction() async {
    if (await utils.isInternetAvailable()) {
      if (await _validateUrlRideBeforeDownload()) {
        await _pdfBloc.downloadPdf(document.url_ride, Theme.of(context).platform);
        setState(() {});
        return;
      }
      _showDialogOk(
          context, 'Download', 'Wait please');
    } else {
      _showDialogOk(context, 'Info',
          'No conection');
    }
  }
  </code></pre>
  <p><strong>bloc/pdf/pdfbloc.dart</strong></p>
  <pre><code>class PdfBloc {
  
    final _downloadingController    = BehaviorSubject&lt;bool&gt;();
    final _loadingController        = BehaviorSubject&lt;bool&gt;();
    final _progressStringController = BehaviorSubject&lt;String&gt;();
    final _pdfProvider              = DownloadProvider();
    
    
    Stream&lt;String&gt; get progressStringStream =&gt; _progressStringController.stream;
    Stream&lt;bool&gt; get loadingStream =&gt; _loadingController.stream;
    Stream&lt;bool&gt; get downloadingStream =&gt; _downloadingController.stream;
  
    Future&lt;ResponseData&gt; downloadPdf(String url, var platform) async {
      _downloadingController.sink.add(true);
      ResponseData resData = await _pdfProvider.downloadPdf(url, _progressStringController, platform);
      _downloadingController.sink.add(false);
      return resData;
    }
  
    dispose() {
      _downloadingController.close();
      _progressStringController.close();
      _loadingController.close();
    }
  }
  </code></pre>
  <p><strong>provider/download/downloadprovider.dart</strong></p>
  <pre><code>class DownloadProvider {
  
    Future&lt;ResponseData&gt; downloadPdf(String url, dynamic progressString, var platform) async {
    ResponseData resData = ResponseData();
    final _prefs = SharedPreferences();
      try {
        var path = await findLocalPath(platform) + '/';
        FlutterDownloader.cancelAll();
        final String taskId = await FlutterDownloader.enqueue(
          url: url,
          savedDir: path,
          showNotification: true, // show download progress in status bar (for Android)
          openFileFromNotification: true, // click on notification to open downloaded file (for Android)
          headers: {HttpHeaders.authorizationHeader: _prefs.token, 'Content-type': 'application/json'},
        );
  
        // Last developer used this &quot;while&quot; to wait while a dialog is shown
        // Android behaviour: flutter says &quot;only success task can be opened&quot; but then it works
        // iOS behaviour: flutter says &quot;only success task can be opened&quot; infinitely and never 
        // shows the pdf
  
        // In iOS this loop iterates forever
        while(!await FlutterDownloader.open(taskId: taskId,)) {
          // Last developer did this validation, but I don't know why
          if (platform == TargetPlatform.iOS) {
            await FlutterDownloader.open(taskId: taskId);
          }
        }
        _setResponseData(resData, 'Completed', false);
        return resData;
      } catch(e) {
        _setResponseData(resData, 'Error', true);
        return resData;
      }
    }
  
    _setResponseData(ResponseData resData, String message, bool state) {
      resData.setData(message);
      resData.setError(state);
    }
  
  }
  </code></pre>
  <pre><code>Future&lt;String&gt; findLocalPath(var platform) async {
    final directory = platform == TargetPlatform.android
        ? await getExternalStorageDirectory()
        : await getApplicationDocumentsDirectory();
    return directory.path;
  }
  
  </code></pre>
  <p>I have tried several versions of ios and iphone without success.</p>
  <p>Any ideas?
  Please help me, I'm stuck.</p>
  <p>Thanks.</p>