tilt_alignment_scale 0.1.0
tilt_alignment_scale: ^0.1.0 copied to clipboard
A customizable sensor-driven alignment scale with moving ball (bubble) for horizontal/vertical guidance.
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'),
],
),
),
);
}
}