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 :(
CodePudding user response:
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