Coder Social home page Coder Social logo

Comments (4)

JagritParakh avatar JagritParakh commented on June 10, 2024

Full code:

import 'dart:io';

import 'package:file_manager/file_manager.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    requestStoragePermission();
  }

  Future<void> requestStoragePermission() async {
    final PermissionStatus status = await Permission.storage.request();
    if (status.isGranted) {
        // Permission granted, perform your operations here
      setState(() {
          // You might update UI or trigger some actions upon permission grant
      });
    } else if (status.isDenied) {
        // Permission denied
        // You may want to display a dialog or message to the user explaining why you need this permission
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      themeMode: ThemeMode.dark,
      theme: ThemeData(useMaterial3: true),
      darkTheme: ThemeData(useMaterial3: true, brightness: Brightness.dark),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  final FileManagerController controller = FileManagerController();

  HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return ControlBackButton(
        controller: controller,
      child: Scaffold(
        appBar: AppBar(),
        body: FileManager(
          controller: controller,
          builder: (context, snapshot) {
            final List<FileSystemEntity> entities = snapshot;
            return ListView.builder(
              itemCount: entities.length,
              itemBuilder: (context, index) {
                return Card(
                  child: ListTile(
                    leading: FileManager.isFile(entities[index])
                        ? Icon(Icons.feed_outlined)
                        : Icon(Icons.folder),
                    title: Text(FileManager.basename(entities[index])),
                    onTap: () {
                      if (FileManager.isDirectory(entities[index])) {
                        controller.openDirectory(entities[index]);   // open directory
                      } else {
                        // Perform file-related tasks.
                      }
                    },
                  ),
                );
              },
            );
          },
        ),
      ),
    );
  }
}

from flutter-permission-handler.

Blue-Cheesecake avatar Blue-Cheesecake commented on June 10, 2024

Which version of Android API that you used? I got this similar problem on API 28, and 31 but work fine on API 33, and 34 (Don't know why). Try to test your app on different Android API.

@JagritParakh

from flutter-permission-handler.

JagritParakh avatar JagritParakh commented on June 10, 2024

I'm using Android API 34. I tried using 33 as well but I get the same error

from flutter-permission-handler.

TimHoogstrate avatar TimHoogstrate commented on June 10, 2024

Dear @JagritParakh,

As per documentation:

/// Permission for accessing external storage.
  ///
  /// Depending on the platform and version, the requirements are slightly
  /// different:
  ///
  /// **Android:**
  /// - On Android 13 (API 33) and above, this permission is deprecated and
  /// always returns `PermissionStatus.denied`. Instead use `Permission.photos`,
  /// `Permission.video`, `Permission.audio` or
  /// `Permission.manageExternalStorage`. For more information see our
  /// [FAQ](https://pub.dev/packages/permission_handler#faq).
  /// - Below Android 13 (API 33), the `READ_EXTERNAL_STORAGE` and
  /// `WRITE_EXTERNAL_STORAGE` permissions are requested (depending on the
  /// definitions in the AndroidManifest.xml) file.
  ///
  /// **iOS:**
  /// - Access to folders like `Documents` or `Downloads`. Implicitly granted.
  static const storage = Permission._(15);

I'll close this issue for now. Feel free to reopen when new information becomes available.

Kind regards,

from flutter-permission-handler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.