magnetic_sensor_lite 0.0.2 copy "magnetic_sensor_lite: ^0.0.2" to clipboard
magnetic_sensor_lite: ^0.0.2 copied to clipboard

PlatformAndroid

A Flutter plugin to check if the device has a magnetic sensor and stream data.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:magnetic_sensor_lite/magnetic_sensor_lite.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Magnetic Sensor Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              FutureBuilder<bool>(
                future: MagneticSensorLite.hasMagneticSensor(),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return const CircularProgressIndicator();
                  } else if (snapshot.hasError) {
                    return Text('Error: ${snapshot.error}');
                  } else {
                    return Text('Has magnetic sensor: ${snapshot.data}');
                  }
                },
              ),
              StreamBuilder<List<double>>(
                stream: MagneticSensorLite.magneticSensorStream,
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return const CircularProgressIndicator();
                  } else if (snapshot.hasError) {
                    return Text('Error: ${snapshot.error}');
                  } else {
                    return Text('Magnetic Sensor Data: ${snapshot.data}');
                  }
                },
              ),
              const ElevatedButton(
                onPressed: MagneticSensorLite.startMagneticSensor,
                child: Text('Start Magnetic Sensor'),
              ),
              const ElevatedButton(
                onPressed: MagneticSensorLite.stopMagneticSensor,
                child: Text('Stop Magnetic Sensor'),
              ),
              const MyCompass(),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
115
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to check if the device has a magnetic sensor and stream data.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface, vector_math

More

Packages that depend on magnetic_sensor_lite

Packages that implement magnetic_sensor_lite