gravity_sensor 1.0.1 copy "gravity_sensor: ^1.0.1" to clipboard
gravity_sensor: ^1.0.1 copied to clipboard

Flutter plugin to access the gravity sensor of the device.

example/lib/main.dart

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

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('gravity_sensor example app'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: StreamBuilder(
            stream: GravitySensor().gravityEvents,
            builder: (_, snapshot) {
              if (snapshot.hasError) return Center(child: Text('Error: ${snapshot.error}'));

              final GravityEvent? data = snapshot.data;
              if (data == null) return const Center(child: Text('No data'));

              return Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const Padding(
                      padding: EdgeInsets.only(right: 16),
                      child: Column(
                        children: <Widget>[
                          Text('x:'),
                          Text('y:'),
                          Text('z:'),
                        ],
                      ),
                    ),
                    Column(
                      children: <Widget>[
                        Text(data.x.toStringAsFixed(5)),
                        Text(data.y.toStringAsFixed(5)),
                        Text(data.z.toStringAsFixed(5)),
                      ],
                    ),
                  ],
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
1
likes
140
points
15
downloads

Publisher

verified publishermadbrains.ru

Weekly Downloads

Flutter plugin to access the gravity sensor of the device.

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #native #gravity #sensor #utils

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gravity_sensor