motion_sensors

Flutter plugin for accessing the Android and iOS accelerometer, gyroscope, magnetometer and orientation sensors. Updated version from https://github.com/zesage/motion_sensors

Getting Started

This release targets Flutter >=3.41.0 and Dart >=3.11.0 because the iOS implementation now relies on Swift Package Manager integration generated by recent Flutter toolchains.

To use this plugin, add dchs_motion_sensors as a dependency in your pubspec.yaml file.

dependencies:
  motion_sensors: ^2.0.2

Import to your project.

import 'package:dchs_motion_sensors/dchs_motion_sensors.dart';

motionSensors.magnetometer.listen((MagnetometerEvent event) {
    print(event);
});

Example iOS With Swift Package Manager

The example app under example/ can be regenerated with the current Flutter iOS template, which wires plugins through Swift Package Manager instead of CocoaPods.

From example/ run:

rm -rf ios
flutter create --platforms=ios --project-name example .
flutter build ios --simulator

After regeneration, the Podfile and Pods references disappear from the iOS host app and the Xcode project uses the local FlutterGeneratedPluginSwiftPackage package instead.

Upgrade Note

If you are upgrading from an older release of this plugin and your iOS app or example was created from a CocoaPods-based Flutter template, regenerate the ios/ host project with a current Flutter SDK before testing or publishing the plugin update on iOS.

In practice, this means using Flutter 3.41 or newer and rerunning flutter create --platforms=ios . inside the app or example directory so the Xcode project picks up the Swift Package Manager wiring.