step_slider 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

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 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: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]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/slider.dart.

Run flutter format to format lib/src/slider.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
collection ^1.14.11 1.14.11 1.14.12
flutter 0.0.0
quiver_hashcode ^2.0.0 2.0.0
Transitive dependencies
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test