我试图将文档下载到Android的本地存储中,但得到了一个错误:
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>
以下是代码:
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);
},
据我所知,我需要获得本地存储路径,然后使用writeToFile()方法从writeToFile引用中保存文件。但是当我试图检查它是否有效时,我会得到一个错误。也许我需要允许吗?我不明白这个错误是怎么回事
发布于 2022-06-21 16:44:20
如果您正在查看真正的android设备,请尝试指定权限。
<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" />
<应用
android->app->src->main->AndroidManifest.xml
发布于 2022-09-29 17:45:51
试试这个。
将其添加到pubspec.yml
文件中“
dependency_overrides:
firebase_core_platform_interface: 4.4.1
这对我有用。
https://stackoverflow.com/questions/72704184
复制相似问题