numberpicker 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 97

NumberPicker Build Status Coverage Status

NumberPicker is a custom widget designed for choosing an integer or decimal number by scrolling spinners.

It is possible to use NumberPicker as a standalone widget as well as in NumberPickerDialog. vertical

Getting Started #

Creating NumberPicker Widget #

new NumberPicker.integer(
                initialValue: 50,
                minValue: 0,
                maxValue: 100,
                onChanged: _handleChange)

Creating NumberPickerDialog (use in material's showDialog method) #

new NumberPickerDialog.decimal(
          minValue: 1,
          maxValue: 10,
          initialDoubleValue: _currentPrice),

Usage examples #

See examples directory for full examples.

Standalone widget #

vertical

class _MyHomePageState extends State<MyHomePage> {
  int _currentValue = 1;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new NumberPicker.integer(
                initialValue: _currentValue,
                minValue: 0,
                maxValue: 100,
                onChanged: (newValue) =>
                    setState(() => _currentValue = newValue)),
            new Text("Current number: $_currentValue"),
          ],
        ),
      ),
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
    );
  }
}

Dialog #

vertical

class _MyHomePageState extends State<MyHomePage> {
  double _currentPrice = 1.0;

  void _showDialog() {
    showDialog<int>(
      context: context,
      builder: (BuildContext context) {
        return new NumberPickerDialog.decimal(
          minValue: 1,
          maxValue: 10,
          title: new Text("Pick a new price"),
          initialDoubleValue: _currentPrice,
        );
      }
    ).then((int value)) {
      if (value != null) {
        setState(() => _currentPrice = value);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Text("Current price: $_currentPrice \$"),
      ),
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.attach_money),
        onPressed: _showDialog,
      ),
    );
  }
}

[1.0.0]

  • Added infinite loop option

[0.1.7]

  • Fixed step bug

[0.1.6]

  • Updated environment sdk dependency

[0.1.5]

  • Added step paramater for integer picker

[0.1.4]

  • Solved normalizing decimal places bug

[0.1.3]

  • Fixed issue with small integer ranges

[0.1.2]

  • Added environment restrictions

[0.1.1]

  • Fixed iOS overscroll bug
  • Updated example's dependencies

[0.1.0]

  • NEW: Initial Release.

example/lib/example.dart

import 'dart:async';

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

void main() {
  runApp(new ExampleApp());
}

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'NumberPicker Example',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'NumberPicker Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIntValue = 10;
  int _currentInfIntValue = 10;
  double _currentDoubleValue = 3.0;
  NumberPicker integerNumberPicker;
  NumberPicker integerInfiniteNumberPicker;
  NumberPicker decimalNumberPicker;

  @override
  Widget build(BuildContext context) {
    integerNumberPicker = new NumberPicker.integer(
      initialValue: _currentIntValue,
      minValue: 0,
      maxValue: 100,
      step: 10,
      onChanged: (value) => setState(() => _currentIntValue = value),
    );
    integerInfiniteNumberPicker = new NumberPicker.integer(
      initialValue: _currentInfIntValue,
      minValue: 0,
      maxValue: 99,
      step: 10,
      infiniteLoop: true,
      onChanged: (value) => setState(() => _currentInfIntValue = value),
    );
    decimalNumberPicker = new NumberPicker.decimal(
      initialValue: _currentDoubleValue,
      minValue: 1,
      maxValue: 5,
      decimalPlaces: 2,
      onChanged: (value) => setState(() => _currentDoubleValue = value),
    );
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          new Row(children: <Widget>[
            Expanded(
              child: Column(children: <Widget>[
                Text("Default"),
                integerNumberPicker,
                new RaisedButton(
                  onPressed: () => _showIntDialog(),
                  child: new Text("Current int value: $_currentIntValue"),
                ),
              ]),
            ),
            Expanded(
              child: Column(children: <Widget>[
                Text("With infinite loop"),
                integerInfiniteNumberPicker,
                new RaisedButton(
                  onPressed: () => _showInfIntDialog(),
                  child: new Text("Current int value: $_currentInfIntValue"),
                ),
              ]),
            ),
          ]),
          decimalNumberPicker,
          new RaisedButton(
            onPressed: () => _showDoubleDialog(),
            child: new Text("Current double value: $_currentDoubleValue"),
          ),
        ],
      ),
    );
  }

  Future _showIntDialog() async {
    await showDialog<int>(
      context: context,
      builder: (BuildContext context) {
        return new NumberPickerDialog.integer(
          minValue: 0,
          maxValue: 100,
          step: 10,
          initialIntegerValue: _currentIntValue,
        );
      },
    ).then((num value) {
      if (value != null) {
        setState(() => _currentIntValue = value);
        integerNumberPicker.animateInt(value);
      }
    });
  }

  Future _showInfIntDialog() async {
    await showDialog<int>(
      context: context,
      builder: (BuildContext context) {
        return new NumberPickerDialog.integer(
          minValue: 0,
          maxValue: 99,
          step: 10,
          initialIntegerValue: _currentInfIntValue,
          infiniteLoop: true,
        );
      },
    ).then((num value) {
      if (value != null) {
        setState(() => _currentInfIntValue = value);
        integerInfiniteNumberPicker.animateInt(value);
      }
    });
  }

  Future _showDoubleDialog() async {
    await showDialog<double>(
      context: context,
      builder: (BuildContext context) {
        return new NumberPickerDialog.decimal(
          minValue: 1,
          maxValue: 5,
          decimalPlaces: 2,
          initialDoubleValue: _currentDoubleValue,
          title: new Text("Pick a decimal number"),
        );
      },
    ).then((num value) {
      if (value != null) {
        setState(() => _currentDoubleValue = value);
        decimalNumberPicker.animateInt(value);
      }
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  numberpicker: ^1.0.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:numberpicker/numberpicker.dart';
  
Version Uploaded Documentation Archive
1.0.0 Jan 16, 2019 Go to the documentation of numberpicker 1.0.0 Download numberpicker 1.0.0 archive
0.1.7 Sep 7, 2018 Go to the documentation of numberpicker 0.1.7 Download numberpicker 0.1.7 archive
0.1.6 Aug 18, 2018 Go to the documentation of numberpicker 0.1.6 Download numberpicker 0.1.6 archive
0.1.5 Aug 8, 2018 Go to the documentation of numberpicker 0.1.5 Download numberpicker 0.1.5 archive
0.1.4 Jun 4, 2018 Go to the documentation of numberpicker 0.1.4 Download numberpicker 0.1.4 archive
0.1.3 May 23, 2018 Go to the documentation of numberpicker 0.1.3 Download numberpicker 0.1.3 archive
0.1.2 May 17, 2018 Go to the documentation of numberpicker 0.1.2 Download numberpicker 0.1.2 archive
0.1.0 Aug 7, 2017 Go to the documentation of numberpicker 0.1.0 Download numberpicker 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
96
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

We analyzed this package on May 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/numberpicker.dart. (-1 points)

Analysis of lib/numberpicker.dart reported 2 hints:

line 397 col 35: The member 'activity' can only be used within instance members of subclasses of 'package:flutter/src/widgets/scroll_position.dart'.

line 397 col 35: The member 'activity' can only be used within 'package:flutter/src/widgets/scroll_position.dart' or a test.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
flutter 0.0.0
infinite_listview ^1.0.0 1.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test