Bird
Raised Fist0
Fluttermobile~20 mins

Permissions handling in Flutter - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Permissions Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What happens when permission is denied in this Flutter code?
Consider this Flutter snippet that requests camera permission. What will the app do if the user denies the permission?
Flutter
import 'package:permission_handler/permission_handler.dart';

Future<void> checkCameraPermission() async {
  var status = await Permission.camera.status;
  if (!status.isGranted) {
    var result = await Permission.camera.request();
    if (result.isDenied) {
      print('Permission denied');
    } else if (result.isGranted) {
      print('Permission granted');
    }
  } else {
    print('Permission already granted');
  }
}
AThe app prints 'Permission granted' even if denied.
BThe app prints 'Permission denied' and does not access the camera.
CThe app automatically retries requesting permission until granted.
DThe app crashes because permission denial is not handled.
Attempts:
2 left
💡 Hint
Think about what the code does when result.isDenied is true.
🧠 Conceptual
intermediate
1:30remaining
Which permission status indicates the user permanently denied permission?
In Flutter's permission_handler package, which status means the user denied permission and selected 'Don't ask again'?
APermissionStatus.denied
BPermissionStatus.limited
CPermissionStatus.restricted
DPermissionStatus.permanentlyDenied
Attempts:
2 left
💡 Hint
This status means the app cannot request permission again without user action in settings.
❓ lifecycle
advanced
2:00remaining
When should you check permissions in a Flutter app lifecycle?
You want to check and request location permission in your Flutter app. When is the best lifecycle moment to do this to ensure permission is up to date?
AOnly once in main() before runApp()
BOnly when the user taps a button to use location
CEvery time the app resumes from background
DOnly after the app has been running for 5 minutes
Attempts:
2 left
💡 Hint
Permissions can change while app is in background.
🔧 Debug
advanced
2:00remaining
Why does this Flutter permission request code never print 'Permission granted'?
Review this code snippet. It requests microphone permission but never prints 'Permission granted' even when permission is granted.
Flutter
import 'package:permission_handler/permission_handler.dart';

Future<void> requestMic() async {
  var status = await Permission.microphone.request();
  if (status == PermissionStatus.granted) {
    print('Permission granted');
  } else if (status == PermissionStatus.denied) {
    print('Permission denied');
  }
}
AThe function is not marked async, so await does not work.
BPermission.microphone.request() returns a Future<PermissionStatus?>, so await is missing.
CPermissionStatus.granted is not the correct enum value for granted permission.
DThe code uses '==' to compare enums instead of '.isGranted' property.
Attempts:
2 left
💡 Hint
Check the function signature and usage of await.
❓ navigation
expert
2:30remaining
How to navigate user to app settings when permission is permanently denied?
In Flutter, if a user permanently denies camera permission, how can you open the app settings screen so they can manually enable it?
AUse openAppSettings() from permission_handler package.
BUse Navigator.pushNamed(context, '/settings') to open settings.
CCall SystemNavigator.pop() to close app and ask user to reopen.
DUse launchUrl('app-settings:') from url_launcher package.
Attempts:
2 left
💡 Hint
permission_handler provides a built-in method for this.

Practice

(1/5)
1. What is the main purpose of handling permissions in a Flutter app?
easy
A. To create animations for UI elements
B. To safely access sensitive device features like camera or location
C. To change the app's theme dynamically
D. To improve app performance by caching data

Solution

  1. Step 1: Understand app permissions

    Permissions allow apps to access sensitive features like camera, microphone, or location safely.
  2. Step 2: Identify the purpose in Flutter apps

    Handling permissions ensures the app asks user consent before accessing these features.
  3. Final Answer:

    To safely access sensitive device features like camera or location -> Option B
  4. Quick Check:

    Permissions = Safe access to sensitive features [OK]
Hint: Permissions control access to device features safely [OK]
Common Mistakes:
  • Confusing permissions with UI customization
  • Thinking permissions improve performance
  • Assuming permissions are for animations
2. Which Flutter package is commonly used to check and request permissions?
easy
A. http
B. provider
C. permission_handler
D. shared_preferences

Solution

  1. Step 1: Identify permission packages

    The permission_handler package is designed to manage permissions in Flutter.
  2. Step 2: Exclude unrelated packages

    http is for network calls, provider for state management, and shared_preferences for local storage.
  3. Final Answer:

    permission_handler -> Option C
  4. Quick Check:

    Permission package = permission_handler [OK]
Hint: permission_handler manages permissions in Flutter [OK]
Common Mistakes:
  • Choosing http for permissions
  • Confusing provider with permission handling
  • Using shared_preferences for permissions
3. What will the following Flutter code print if the camera permission is granted?
var status = await Permission.camera.status;
if (status.isGranted) {
  print('Camera permission granted');
} else {
  print('Camera permission denied');
}
medium
A. Syntax error
B. Camera permission denied
C. Permission status unknown
D. Camera permission granted

Solution

  1. Step 1: Check permission status

    The code checks if camera permission is granted using status.isGranted.
  2. Step 2: Determine output for granted permission

    If granted, it prints 'Camera permission granted'. Otherwise, it prints denial message.
  3. Final Answer:

    Camera permission granted -> Option D
  4. Quick Check:

    Granted permission prints granted message [OK]
Hint: isGranted true means permission granted [OK]
Common Mistakes:
  • Confusing isGranted with isDenied
  • Expecting syntax error
  • Ignoring async await usage
4. Identify the error in this Flutter code snippet for requesting location permission:
var status = await Permission.location.request();
if (status == PermissionStatus.granted) {
  print('Permission granted');
} else {
  print('Permission denied');
}
medium
A. No error, code is correct
B. Using == to compare PermissionStatus instead of isGranted property
C. Permission.location.request() does not exist
D. Missing await keyword before request()

Solution

  1. Step 1: Review permission request syntax

    The request() method returns a PermissionStatus which can be compared using ==.
  2. Step 2: Confirm code correctness

    The code correctly awaits the request and compares status to PermissionStatus.granted.
  3. Final Answer:

    No error, code is correct -> Option A
  4. Quick Check:

    Permission request syntax is correct [OK]
Hint: PermissionStatus can be compared with == safely [OK]
Common Mistakes:
  • Thinking isGranted must be used instead of ==
  • Forgetting await before request()
  • Assuming request() method does not exist
5. You want to show a message to the user only if the app has both camera and microphone permissions granted. Which Flutter code snippet correctly checks this using permission_handler?
hard
A. if (await Permission.camera.isGranted && await Permission.microphone.isGranted) { print('All permissions granted'); }
B. if (await Permission.camera.request() && await Permission.microphone.request()) { print('All permissions granted'); }
C. if (Permission.camera.isGranted && Permission.microphone.isGranted) { print('All permissions granted'); }
D. if (Permission.camera.status.isGranted && Permission.microphone.status.isGranted) { print('All permissions granted'); }

Solution

  1. Step 1: Understand async permission checks

    Checking isGranted requires awaiting because it returns a Future<bool>.
  2. Step 2: Analyze each option

    if (await Permission.camera.isGranted && await Permission.microphone.isGranted) { print('All permissions granted'); } correctly awaits both permissions' isGranted properties. if (await Permission.camera.request() && await Permission.microphone.request()) { print('All permissions granted'); } incorrectly awaits request() which returns PermissionStatus, not bool. if (Permission.camera.isGranted && Permission.microphone.isGranted) { print('All permissions granted'); } misses await, causing errors. if (Permission.camera.status.isGranted && Permission.microphone.status.isGranted) { print('All permissions granted'); } accesses status without await, which is a Future.
  3. Final Answer:

    if (await Permission.camera.isGranted && await Permission.microphone.isGranted) { print('All permissions granted'); } -> Option A
  4. Quick Check:

    Await isGranted for correct permission check [OK]
Hint: Await isGranted to check permission status correctly [OK]
Common Mistakes:
  • Not awaiting async permission checks
  • Using request() instead of isGranted for condition
  • Accessing status without await
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard