Skip to content

Instantly share code, notes, and snippets.

@repentsinner
Created August 29, 2019 19:21
Show Gist options
  • Save repentsinner/3b635247f37c28f11a6a3a9700ec781d to your computer and use it in GitHub Desktop.
Save repentsinner/3b635247f37c28f11a6a3a9700ec781d to your computer and use it in GitHub Desktop.
Flutter Slider/RangeSlider test
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Slider/RangeSlider Test'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const int divisions = 35;
double _value = 0.0;
RangeValues _values = RangeValues(0.0, divisions.toDouble());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Slider(
min: 0.0,
max: divisions.toDouble(),
divisions: divisions,
value: _value,
onChanged: (double value) {
setState(() {
_value = value;
});
},
),
Text('$_value'),
RangeSlider(
min: 0.0,
max: divisions.toDouble(),
divisions: divisions,
values: _values,
onChanged: (RangeValues value) {
print(_values);
setState(() {
_values = value;
});
},
),
Text(
'$_values',
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment