我试图使上传功能,所以用户可以上传文件到firebase帐户在过去,它运行良好,但昨天,它不会显示文件
这就是密码
uploadImage() async {
final storage = FirebaseStorage.instance;
final picker = ImagePicker();
PickedFile? image;
//Check Permissions
await Permission.photos.request();
var permissionStatus = await Permission.photos.status;
if (permissionStatus.isGranted) {
//Select Image
image = await picker.getImage(source: ImageSource.gallery);
var file = File(image!.path);
final fileName = basename(file.path);
final destination = 'user/$emaila/identitas/$fileName';
if (image != null) {
//Upload to Firebase
var snapshot = await storage
.ref()
.child(destination)
.putFile(file)
.whenComplete(() => null);
var downloadUrl = await snapshot.ref.getDownloadURL();
setState(() {
imageUrlidentitas = downloadUrl;
});
} else {
print('No Path Received');
}
} else {
print('Grant Permissions and try again');
}
}
这是android清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rekammedis">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Permissions options for the `storage` group -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<!-- Permissions options for the `camera` group -->
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:label="rekammedis"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
编译器会说
D/权限处理程序(9318):在清单中找不到以下项的权限:[]9 D/权限处理程序(9318):在清单中找不到以下项的权限:[]9 I/扑动(9318):授予权限并重试
怎么解决?有人知道吗?
我试着在stackoverflow中查找,但没有一个解释答案
2条答案
按热度按时间sshcrbum1#
检查
build.gradle
文件中的targetSdkVersion。如果您使用的是
targetSdkVersion = 30
,那么您将需要以不同的方式获得写入存储权限,我认为您可以尝试本文中讨论的解决方案goqiplq22#
这是最近的一个bug,是由10.2.0中的新版本permissionhandler引入的。在这里讨论https://github.com/Baseflow/flutter-permission-handler/issues/944,我也会复制这个问题的答案。这个解决方案对我来说也是有效的。
当设备是Android 12.0或更低版本时,我通过检查Permissions.storage.status修复了这个问题,否则我使用Permissions.photos.status。我使用device_info_plus插件检查Android版本:
我在AndroidManifest.kt中添加了以下内容
在扑动中:
github上的所有学分属于HinrikHelga