Customizable Flutter number picker using buttons instead of scroll.
- Head to
/pubspec.yaml
and addbutton_picker: ^0.1.0
below dependencies like this:
dependencies:
flutter:
sdk: flutter
button_picker: ^0.1.0
- Run
flutter packages get
or use the GUI equivalent - Now in your code
import 'package:button_picker/button_picker.dart';
- You're ready to go!
ButtonPicker is designed to be customizable.
import 'package:flutter/material.dart';
import 'package:button_picker/button_picker.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ButtonPicker(
minValue: 0,
maxValue: 99,
initialValue: 0,
onChanged: (val) => print(val),
step: 2.5,
horizontal: false,
loop: true,
padding: 5.0,
iconUp: Icons.keyboard_arrow_up,
iconDown: Icons.keyboard_arrow_down,
iconLeft: Icons.keyboard_arrow_left,
iconRight: Icons.keyboard_arrow_right,
iconUpRightColor: Colors.blue,
iconDownLeftColor: Colors.blue,
style: TextStyle(
fontSize: 48.0,
color: Colors.blue
),
),
),
),
);
}
}
minValue
[required] is the minimum value of the ButtonPicker.maxValue
[required] is the maximum value of the ButtonPicker.initialValue
[required] is the value displayed on load.onChanged
[required] returns the current value.step
defines how much the value should increase or decrease on tap.horizontal
renders a horizontal ButtonPicker when set totrue
.loop
lets the ButtonPicker count from the beginning when passingmaxValue
or from the end when passingminValue
when set totrue
.padding
defines the space between the buttons and the value.iconUp
,iconDown
,iconLeft
andiconRight
are the actual icons.iconUpRightColor
is the color of the upper button whenhorizontal == false
and the color of the right button whenhorizontal == true
.iconDownLeftColor
is the color of the lower button whenhorizontal == false
and the color of the left button whenhorizontal == true
.style
is theTextStyle
of the value.
Note: When both initialValue
and step
are integers, the value won't have any decimals.