0Pricing
Flutter Mobile Development · Lesson

Permissions & Sensors

Request runtime permissions and read device sensors like the accelerometer in Flutter to build context-aware, platform-integrated apps.

Permissions & Sensors is a free Flutter Mobile Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flutter Mobile Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Permissions & Sensors?

Many platform features — camera, location, sensors — require runtime permission. And sensors like the accelerometer let your app react to physical movement.

The permission_handler Package

The permission_handler package gives a unified API for requesting and checking permissions across Android and iOS.

dependencies:
  permission_handler: ^11.0.0

Checking Status

Check whether a permission is granted before using a feature.

final status = await Permission.camera.status;
if (status.isGranted) {
  openCamera();
}

Requesting a Permission

Call request() to prompt the user. Always handle a denial gracefully.

final result = await Permission.location.request();
if (result.isGranted) {
  startTracking();
}

Permanently Denied

If the user permanently denies, you cannot re-prompt — send them to settings instead.

if (status.isPermanentlyDenied) {
  await openAppSettings();
}

Declaring Permissions

You must also declare permissions natively: AndroidManifest.xml on Android and Info.plist usage descriptions on iOS.

<!-- Android -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- iOS Info.plist -->
<key>NSCameraUsageDescription</key>
<string>We need the camera to scan codes</string>

Meet the Sensors

The sensors_plus package exposes device motion sensors as streams.

  • Accelerometer
  • Gyroscope
  • Magnetometer
dependencies:
  sensors_plus: ^4.0.0

Reading the Accelerometer

Subscribe to the accelerometer stream to get x, y, z acceleration values.

accelerometerEventStream().listen((event) {
  print('x: ' + event.x.toString() + ' y: ' + event.y.toString());
});

The Gyroscope

The gyroscope reports rotation rate around each axis — useful for tilt and orientation effects.

gyroscopeEventStream().listen((event) {
  print('rotation: ' + event.x.toString());
});

Detecting a Shake

Combine accelerometer axes into a magnitude and compare against a threshold to detect a shake gesture.

import 'dart:math';

void onEvent(AccelerometerEvent e) {
  final magnitude = sqrt(e.x * e.x + e.y * e.y + e.z * e.z);
  if (magnitude > 15) onShake();
}

Cleaning Up Subscriptions

Sensor streams keep firing — cancel the subscription in dispose to save battery.

late StreamSubscription sub;
@override
void dispose() {
  sub.cancel();
  super.dispose();
}

Quick Check

The user permanently denied location. What should your app do?

Recap

You learned permissions and sensors:

  • permission_handler: status, request, openAppSettings
  • Native declarations on Android and iOS
  • sensors_plus accelerometer and gyroscope streams
  • Shake detection and cleanup

Your apps can now responsibly access platform capabilities.

Frequently asked questions

Is the “Permissions & Sensors” lesson free?

Yes — the full text of “Permissions & Sensors” is free to read here on the web, and the Flutter Mobile Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flutter Mobile Development course, upgrade to CoddyKit PRO.

What will I learn in “Permissions & Sensors”?

Request runtime permissions and read device sensors like the accelerometer in Flutter to build context-aware, platform-integrated apps. You practise Flutter Mobile Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Flutter Mobile Development?

No prior experience is required. Flutter Mobile Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Permissions & Sensors” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Flutter Mobile Development lesson?

Yes. Every Flutter Mobile Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Platform Channels (MethodChannel)
  2. Geolocation & Camera Plugins
  3. Native UI Integration
  4. Permissions & Sensors
← Back to Flutter Mobile Development