1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
thesis_shop/lib/widgets/number_picker.dart

52 lines
1.3 KiB

import 'package:flutter/material.dart';
class NumberPicker extends StatelessWidget {
final int value;
final VoidCallback onUp;
final VoidCallback onDown;
final int minValue;
final int maxValue;
const NumberPicker({
Key? key,
required this.value,
required this.onUp,
required this.onDown,
this.minValue = 0,
this.maxValue = 100,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_ConditionalIconButton(
enabled: value > minValue, onClick: onDown, iconData: Icons.remove),
Text(value.toString()),
_ConditionalIconButton(
enabled: value < maxValue, onClick: onUp, iconData: Icons.add),
],
);
}
}
class _ConditionalIconButton extends StatelessWidget {
final bool enabled;
final VoidCallback onClick;
final IconData iconData;
const _ConditionalIconButton({
Key? key,
required this.enabled,
required this.onClick,
required this.iconData,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return IconButton(
onPressed: enabled ? onClick : null,
icon: Icon(iconData),
);
}
}