flutter_scale_ruler

A simple scale ruler for adding length in feet and inches and cms (pub.dev).

The public API is documented on the classes and fields in lib/flutter_scale_ruler.dart. Those /// comments are the API reference published with the package.

Features

  • Centimeters, or feet and inches, on a horizontal or vertical ruler.
  • majorTickInterval spaces the numbered ticks.
  • showValueIndicator shows the selection beside the thumb while dragging.
  • ScaleValue.label reads 4 ft 2 in or 40 cm.
  • ScaleRulerController moves the thumb from a button or another control.
  • onChangeStart, onChangeEnd, and enabled match a normal slider.
final controller = ScaleRulerController();

ScaleRuler.lengthMeasurement(
  minValue: 0,
  maxValue: 200,
  initialValue: 170,
  controller: controller,
  majorTickInterval: 10,
  showValueIndicator: true,
  onChanged: (ScaleValue value) {
    debugPrint(value.label);
  },
);

controller.setCentimeters(180);

Screenshots

Usage

Example

To use this package :

dependencies:
   flutter:
     sdk: flutter
   flutter_scale_ruler:

How to use

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;

  @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,
                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),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Pull Requests

Pull requests are most welcome. It usually will take me within 24-48 hours to respond to any issue or request.

  1. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
  2. Pull requests must be made against develop branch. Any other branch (unless specified by the maintainers) will get rejected.

Created & Maintained By

Boffin Coders Pvt. Ltd.

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of :coffee:

License

Copyright 2018 Boffin Coders Pvt. Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Libraries

flutter_scale_ruler
A ruler widget for choosing a length in centimeters or in feet and inches.