flutter_scale_ruler 1.1.0 copy "flutter_scale_ruler: ^1.1.0" to clipboard
flutter_scale_ruler: ^1.1.0 copied to clipboard

A simple scale ruler for adding length in feet and inches and cms.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Scale Ruler',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
      ),
      home: const MyHomePage(title: 'Flutter Scale Ruler'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ScaleValue? _scaleValue;
  ScaleValue? _scaleValueCms;
  final _cmController = ScaleRulerController();

  @override
  void dispose() {
    _cmController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                _scaleValue?.label ?? '0 ft 0 in',
                style: const TextStyle(fontSize: 18.0),
              ),
              const SizedBox(height: 20.0),
              ScaleRuler.lengthMeasurement(
                maxValue: 8,
                minValue: 0,
                initialValue: 4,
                isFeet: true,
                axis: Axis.vertical,
                stepIndicatorColor: Colors.brown,
                stepIndicatorDividerColor: Colors.blue,
                onChanged: (ScaleValue scaleValue) {
                  if (mounted) {
                    setState(() {
                      _scaleValue = scaleValue;
                    });
                    debugPrint(scaleValue.label);
                  }
                },
              ),
              const SizedBox(height: 20.0),
              ScaleRuler.lengthMeasurement(
                maxValue: 80,
                minValue: 0,
                initialValue: 40,
                controller: _cmController,
                majorTickInterval: 10,
                showValueIndicator: true,
                axis: Axis.horizontal,
                backgroundColor: Colors.yellow[500]!,
                sliderActiveColor: Colors.green[500]!,
                sliderInactiveColor: Colors.greenAccent,
                onChanged: (ScaleValue scaleValue) {
                  if (mounted) {
                    setState(() {
                      _scaleValueCms = scaleValue;
                    });
                    debugPrint(scaleValue.label);
                  }
                },
              ),
              const SizedBox(height: 20.0),
              Text(
                _scaleValueCms?.label ?? '0 cm',
                style: const TextStyle(fontSize: 18.0),
              ),
              TextButton(
                onPressed: () => _cmController.setCentimeters(60),
                child: const Text('Set to 60 cm'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
22
likes
160
points
347
downloads

Documentation

API reference

Publisher

verified publisherboffincoders.com

Weekly Downloads

A simple scale ruler for adding length in feet and inches and cms.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_scale_ruler