step_slider 1.0.0+1

step_slider #

Flutter slider widget that snaps to given step values and notifies about step changes.

StepSlider demo

Getting Started #

Add StepSlider to your widget tree along with needed custom arguments:

@override
Widget build(BuildContext context) {
    ...
    child: StepSlider(
        min: 100.0,
        max: 200.0,
        steps: {110, 150, 160, 195},
        initialStep: 150,
        animCurve: Curves.bounceInOut,
        animDuration: Duration(seconds: 1),
        snapMode: SnapMode.value(10),
        hardSnap: true,
        onStepChanged: (it) => print('Step changed to $it.'),
        // ... slider's other args
    ),
}

[1.0.0+1] - 15/04/2019

  • Implement core functionality.

example/main.dart

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

void main() => runApp(SliderExample());

class SliderExample extends StatefulWidget {
  @override
  _SliderExampleState createState() => _SliderExampleState();
}

class _SliderExampleState extends State<SliderExample> {
  double _currentStep = 150.0;
  SnapMode _snapMode = SnapMode.stretch();
  bool _hardSnap = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'StepSlider example',
      home: Scaffold(
        appBar: AppBar(title: Text('StepSlider example')),
        body: Padding(
          padding: EdgeInsets.all(16.0),
          child: Column(children: <Widget>[
            StepSlider(
              min: 100.0,
              max: 200.0,
              steps: {110, 150, 160, 195},
              initialStep: _currentStep,
              animCurve: Curves.ease,
              animDuration: Duration(seconds: 1),
              snapMode: _snapMode,
              hardSnap: _hardSnap,
              onStepChanged: (it) {
                setState(() => _currentStep = it);
              },
              // ... slider's other args
            ),
            Center(child: Text('Current step: $_currentStep')),
            Container(height: 32.0),
            Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 32.0),
                child: Center(child: Text('Hard snap')),
              ),
              Switch(
                value: _hardSnap,
                onChanged: (it) {
                  setState(() => _hardSnap = it);
                },
              )
            ]),
            Container(height: 16.0),
            Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 32.0),
                child: Center(child: Text('Snap mode')),
              ),
              DropdownButton<SnapMode>(
                value: _snapMode,
                onChanged: (it) {
                  setState(() => _snapMode = it);
                },
                items: [
                  DropdownMenuItem(
                    value: SnapMode.value(5),
                    child: Text('Value'),
                  ),
                  DropdownMenuItem(
                    value: SnapMode.percent(10),
                    child: Text('Percent'),
                  ),
                  DropdownMenuItem(
                    value: SnapMode.stretch(),
                    child: Text('Stretch'),
                  ),
                ],
              )
            ]),
          ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  step_slider: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:step_slider/step_slider.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
37
Learn more about scoring.

This package is not analyzed, because it is discontinued.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0