最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - GalleryBloc not refreshing after granting permission - Stack Overflow

programmeradmin3浏览0评论

I'm working on a Flutter app where users need to grant photo access permission to load gallery images. I'm using Permission.photos for Android 33+ and Permission.storage for older versions. The gallery is managed with Bloc (GalleryBloc).

Problem:

Even after granting permission, the GalleryBloc does not reload the gallery images automatically. I have to restart the app for images to appear.

What I’ve Tried:

  • Called galleryBloc.add(LoadGallery()); after permission is granted.
  • Listened to the GalleryBloc stream to detect state changes.
  • Verified GalleryLoaded state is emitted but the UI does not refresh.
  • Used setState(() {}); inside GalleryLoaded state to force UI rebuild.
  • Manually triggering _onRefreshGallery doesn’t always fetch the latest images.
Future<void> _requestPhotoPermission(BuildContext context) async {
  PermissionStatus status;
  try {
    if (Platform.isAndroid) {
      final deviceInfo = DeviceInfoPlugin();
      final androidInfo = await deviceInfo.androidInfo;
      final androidVersion = androidInfo.version.sdkInt;

      status = (androidVersion >= 33)
          ? await Permission.photos.request()
          : await Permission.storage.request();
    } else {
      status = await Permission.photos.request();
    }

    if (status.isGranted) {
      setState(() {
        _isgrated = true;
      });

      galleryBloc.add(LoadGallery()); // 
发布评论

评论列表(0)

  1. 暂无评论