0

Im working Flutter test path provider directory. But I can't access the .Statuses directory. I have been trying for a long time, but I have not been successful. Do you know what I should do?

Androidmanifest.xml Permission

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
        tools:ignore="ScopedStorage" />

My codes

class AppConstants {
  static String WHATSAPP_PATH= "/storage/emulated/0/Whatsapp/Media/.Statuses";
}
 if(status.isGranted) {
      final directory = await Directory(AppConstants.WHATSAPP_PATH); ///Please attention to this line
      if(directory.existsSync()) {
        final items = directory.listSync();

        if(ext == ".mp4") {
          _getVideos = items.where((element) => element.path.endsWith(".mp4")).toList();
          notifyListeners();
        } else {
          _getImages = items.where((element) => element.path.endsWith(".jpg")).toList();
          notifyListeners();
        }

        _isWhatsappAvailable = true;
        notifyListeners();

        print(items.toString());
      } else {
        print("No Whatsapp Found");
        _isWhatsappAvailable = false;
        notifyListeners();
      }
    }

Image.dart codes

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:van_whatsapp/Provider/getStatusProvide.dart';
import 'package:van_whatsapp/Screen/BottomNavePages/Image/image_view.dart';
import 'package:van_whatsapp/Screen/main_activity.dart';

class ImageHomePage extends StatefulWidget {
  const ImageHomePage({Key? key}) : super(key: key);

  @override
  State<ImageHomePage> createState() => _ImageHomePageState();
}

class _ImageHomePageState extends State<ImageHomePage> {
  bool _isFetched = false;


  @override

  Widget build(BuildContext context) {
    return Scaffold(
      body: Consumer<GetStatusProvider>(
        builder: (context, file, child) {
          if(_isFetched = false) {
            file.getStatus(".jpg");
            Future.delayed(const Duration(microseconds: 1), () {
              _isFetched = true;
            });
          }
          return file.isWhatsappAvailable == false ? const Center(
            child: Text("Whatsapp not available"),
          ) : file.getImages.isEmpty ? const Center(
            child: Text("No image available"),
          ) : Container(
            child: GridView(
              padding: EdgeInsets.all(20),
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2, crossAxisSpacing: 8, mainAxisSpacing: 8),
              children: List.generate(file.getImages.length, (index) {
                final data = file.getImages[index];
                return GestureDetector(
                  onTap: (){
                    Navigator.push(
                        context,
                        CupertinoPageRoute(builder: (_) => const ImageView(),),
                            );
                  },
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.amber,
                      image: DecorationImage(
                        fit: BoxFit.cover,
                        image: FileImage(File(data.path))),
                      borderRadius: BorderRadius.all(
                      Radius.circular(10),
                    ),),
                  ),
                );
              }),
            )
          );
        }
      ),
    );
  }
}

I wanted to access the .Statuses folder and show the pictures. But I can't access the folder.Can you show me where I made a mistake? Or what else can I do.

Hygge
  • 1
  • 1

0 Answers0