From a861c16e8fdc183a2eefa7c7dfe8ca03de1effa8 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 9 Jul 2020 16:50:27 +0200 Subject: [PATCH] PurchaseSlider: Add buttons to make chosing the price easier This way we can more easily choose the value, as the slider is quite buggy. --- lib/widgets/purchase_widget.dart | 60 +++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/widgets/purchase_widget.dart b/lib/widgets/purchase_widget.dart index 93ef6de0..43d0b5d5 100644 --- a/lib/widgets/purchase_widget.dart +++ b/lib/widgets/purchase_widget.dart @@ -192,11 +192,69 @@ class _PurchaseWidgetState extends State { return Column( children: [ - slider, + Row( + children: [ + _PurchaseSliderButton( + icon: Icon(Icons.arrow_left), + onPressed: () { + setState(() { + _selectedOffering = _prevOffering(); + }); + }, + ), + Expanded(child: slider), + _PurchaseSliderButton( + icon: Icon(Icons.arrow_right), + onPressed: () { + setState(() { + _selectedOffering = _nextOffering(); + }); + }, + ), + ], + mainAxisSize: MainAxisSize.max, + ), const SizedBox(height: 16.0), PurchaseButton(_selectedOffering?.monthly), ], mainAxisAlignment: MainAxisAlignment.spaceAround, ); } + + Offering _prevOffering() { + for (var i = 0; i < _offerings.length; i++) { + if (_offerings[i] == _selectedOffering) { + return i > 0 ? _offerings[i - 1] : _offerings[i]; + } + } + + return null; + } + + Offering _nextOffering() { + for (var i = 0; i < _offerings.length; i++) { + if (_offerings[i] == _selectedOffering) { + return i < _offerings.length - 1 ? _offerings[i + 1] : _offerings[i]; + } + } + + return null; + } +} + +class _PurchaseSliderButton extends StatelessWidget { + final Widget icon; + final Function onPressed; + + _PurchaseSliderButton({@required this.icon, @required this.onPressed}); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: icon, + padding: const EdgeInsets.all(0.0), + iconSize: 64.0, + onPressed: onPressed, + ); + } }