flutter_spinbox 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

SpinBox for Flutter #

pub license: MIT build codecov

SpinBox for Flutter is a numeric input widget with an input field for entering a specific value, and spin buttons for quick, convenient, and accurate value adjustments.

Guidelines #

Spin boxes are best suited for such applications

  • that deal with large numeric value ranges and high precisions,
  • where users typically know upfront the exact value they are entering,
  • where users may later have a need to accurately adjust a previously entered value.

As a rule of thumb, spin boxes are great for scenarios where

  • sliders and alike UI controls are too inaccurate,
  • tumblers and alike UI controls cannot provide enough value range,
  • and a plain text field is inconvenient for value adjustments (open the VKB, move the cursor, erase the previous value, enter a new value... vs. tap-tap-done).

Designs #

SpinBox for Flutter comes in two variants. It provides implementations for both designs in Flutter, Material and Cupertino (iOS).

Material Design #

SpinBox

import 'package:flutter_spinbox/material.dart'; // or flutter_spinbox.dart for both

SpinBox(
  min: 1,
  max: 100,
  value: 50,
  onChanged: (value) => print(value),
)

See also Material Components widgets package.

Cupertino (iOS-style) Design #

CupertinoSpinBox

import 'package:flutter_spinbox/cupertino.dart'; // or flutter_spinbox.dart for both

CupertinoSpinBox(
  min: 1,
  max: 100,
  value: 50,
  onChanged: (value) => print(value),
)

See also Cupertino (iOS-style) widgets package.

Usage #

To use this package, add flutter_spinbox as a dependency in your pubspec.yaml file.

[0.2.0] - 2020-05-30 #

  • Introduced CupertinoSpinBox.

[0.1.0] - 2020-05-19 #

  • Initial release.

example/lib/main.dart

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

void main() => runApp(
      MaterialApp(
        debugShowCheckedModeBanner: false,
        home: DefaultTabController(
          length: 2,
          child: Scaffold(
            appBar: AppBar(
              title: Text('SpinBox for Flutter'),
              bottom: TabBar(
                tabs: [
                  Tab(icon: Icon(Icons.swap_horiz)),
                  Tab(icon: Icon(Icons.swap_vert)),
                ],
              ),
            ),
            body: TabBarView(
              children: [
                HorizontalSpinBoxPage(),
                VerticalSpinBoxPage(),
              ],
            ),
          ),
        ),
      ),
    );

class HorizontalSpinBoxPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: ListView(
        children: [
          Padding(
            child: SpinBox(
              value: 10,
              decoration: InputDecoration(labelText: 'Basic'),
            ),
            padding: const EdgeInsets.all(16),
          ),
          Padding(
            child: SpinBox(
              max: 10.0,
              value: 5.0,
              decimals: 1,
              step: 0.1,
              decoration: InputDecoration(labelText: 'Decimals'),
            ),
            padding: const EdgeInsets.all(16),
          ),
          Padding(
            child: SpinBox(
              min: -1.0,
              max: 1.0,
              value: 0.25,
              decimals: 3,
              step: 0.001,
              acceleration: 0.001,
              decoration: InputDecoration(labelText: 'Accelerated'),
            ),
            padding: const EdgeInsets.all(16),
          ),
          Padding(
            child: SpinBox(
              value: 50,
              decoration: InputDecoration(
                hintText: 'Hint',
                labelText: 'Decorated',
                helperText: 'Helper',
                prefixText: 'Prefix',
                suffixText: 'Suffix',
                counterText: 'Counter',
              ),
              validator: (text) => text.isEmpty ? 'Invalid' : null,
            ),
            padding: const EdgeInsets.all(16),
          ),
        ],
      ),
    );
  }
}

class VerticalSpinBoxPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: Center(
        child: ListView(
          shrinkWrap: true,
          children: [
            Center(
              child: Container(
                width: 128,
                child: SpinBox(
                  min: -50,
                  max: 50,
                  value: 15,
                  spacing: 24,
                  direction: Axis.vertical,
                  textStyle: TextStyle(fontSize: 48),
                  incrementIcon: Icon(Icons.keyboard_arrow_up, size: 64),
                  decrementIcon: Icon(Icons.keyboard_arrow_down, size: 64),
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    contentPadding: const EdgeInsets.all(24),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_spinbox: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_spinbox/flutter_spinbox.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_spinbox that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
cupertino_icons ^0.1.3 0.1.3
flutter 0.0.0
intl ^0.16.1 0.16.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test
flutter_test_ui ^1.0.0