tilt_alignment_scale 0.1.0 copy "tilt_alignment_scale: ^0.1.0" to clipboard
tilt_alignment_scale: ^0.1.0 copied to clipboard

A customizable sensor-driven alignment scale with moving ball (bubble) for horizontal/vertical guidance.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      home: const DemoPage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

  @override
  State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  Axis _axis = Axis.horizontal;
  double _angle = 0;
  bool _inRange = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('tilt_alignment_scale demo'),
        actions: <Widget>[
          IconButton(
            onPressed: () {
              setState(() {
                _axis =
                    _axis == Axis.horizontal ? Axis.vertical : Axis.horizontal;
              });
            },
            icon: const Icon(Icons.swap_vert),
            tooltip: 'Toggle Axis',
          ),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            AlignmentScale(
              config: AlignmentScaleConfig(
                axis: _axis,
                ballSize: 28,
                defaultBallColor: Colors.blue,
                angleRangeDegrees: 60,
                showTicks: true,
                showCenterLine: true,
                showGuideLines: true,
                guideLineDegrees: const <double>[15, 35],
                angleColorZones: const <AngleColorZone>[
                  AngleColorZone(minAbsDegrees: 0, ballColor: Colors.green),
                  AngleColorZone(minAbsDegrees: 15, ballColor: Colors.orange),
                  AngleColorZone(minAbsDegrees: 35, ballColor: Colors.red),
                ],
                scaleSize: _axis == Axis.horizontal
                    ? const Size(340, 80)
                    : const Size(80, 340),
              ),
              onAngleUpdate: (double angle, bool inRange) {
                setState(() {
                  _angle = angle;
                  _inRange = inRange;
                });
              },
            ),
            const SizedBox(height: 16),
            Text('Angle: ${_angle.toStringAsFixed(1)}°  | In range: $_inRange'),
          ],
        ),
      ),
    );
  }
}
3
likes
150
points
11
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A customizable sensor-driven alignment scale with moving ball (bubble) for horizontal/vertical guidance.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, sensors_plus

More

Packages that depend on tilt_alignment_scale