Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PlatformException(channel-error, Unable to establish connection on channel., null, null) – saving to local storage

I tried to download document to local storage to Android, but got an error:

E/flutter ( 6441): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
E/flutter ( 6441): #0      PathProviderApi.getApplicationDocumentsPath (package:path_provider_android/messages.g.dart:97:7)
E/flutter ( 6441): <asynchronous suspension>
E/flutter ( 6441): #1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:115:24)
E/flutter ( 6441): <asynchronous suspension>
E/flutter ( 6441): #2      _FileContainerState.build.<anonymous closure>.<anonymous closure>
package:whatsapp_redesign/…/chat/file_container.dart:56
E/flutter ( 6441): <asynchronous suspension>

Here is the code:

  GestureDetector(
                  onTap: () async {
                    // chatBloc.add(SaveFileEvent(widget.message.file!));
                    final dir = await getApplicationDocumentsDirectory();
                    final file =
                        File('${dir.path}/${widget.message.file!.name}');
                    final ref = FirebaseStorage.instance
                        .ref('uploads/${widget.message.file!.name}');
                    await ref.writeToFile(file);
                  },

As I know, I need to get the local storage path and then save file from FireStorage Reference with writeToFile() method. But when I try to check if it works I get an error. Maybe I have to give some permission?
I don’t understand what is this error about 🙁

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try to specify permissions if you are looking at a real android device.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application

Inside android->app->src->main->AndroidManifest.xml

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading