Skip to main content

headless_level 0.3.0 copy "headless_level: ^0.3.0" to clipboard
headless_level: ^0.3.0 copied to clipboard

PlatformiOS

Headless iOS level: a typed stream of the device gravity vector. No widgets, no exceptions, no permissions.

example/lib/main.dart

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

void main() => runApp(const ExampleApp());

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

  @override
  State<ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  final _source = LevelSource();
  LevelSample? _sample;
  bool? _available;

  @override
  void initState() {
    super.initState();
    _source.isAvailable().then((v) {
      if (mounted) setState(() => _available = v);
    });
    _source.watch().listen((s) {
      if (mounted) setState(() => _sample = s);
    });
  }

  @override
  Widget build(BuildContext context) {
    final s = _sample;
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('headless_level')),
        body: Center(
          child: Text(
            s == null
                ? 'available: $_available\nwaiting...'
                : 'available: $_available\n'
                      'gx ${s.gx.toStringAsFixed(3)}\n'
                      'gy ${s.gy.toStringAsFixed(3)}\n'
                      'gz ${s.gz.toStringAsFixed(3)}\n'
                      'tilt ${s.tiltDeg.toStringAsFixed(1)}°',
            textAlign: TextAlign.center,
            style: const TextStyle(fontSize: 20),
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
27
downloads

Documentation

API reference

Publisher

verified publisherlasoai.vn

Weekly Downloads

Headless iOS level: a typed stream of the device gravity vector. No widgets, no exceptions, no permissions.

Repository (GitHub)
View/report issues

Topics

#level #inclinometer #sensors #ios

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on headless_level

Packages that implement headless_level