stack_wallet/lib/widgets/fee_slider.dart

83 lines
1.9 KiB
Dart
Raw Permalink Normal View History

2023-06-17 01:25:49 +00:00
import 'dart:math';
import 'package:flutter/material.dart';
2024-06-16 19:25:07 +00:00
import '../utilities/text_styles.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
2023-06-17 01:25:49 +00:00
2024-06-16 19:25:07 +00:00
/// This has limitations. At least one of [pow] or [min] must be set to 1
2023-06-17 01:25:49 +00:00
class FeeSlider extends StatefulWidget {
const FeeSlider({
super.key,
required this.onSatVByteChanged,
required this.coin,
2024-06-16 19:25:07 +00:00
this.min = 1,
this.max = 5,
this.pow = 4,
2024-05-01 20:59:44 +00:00
this.showWU = false,
2024-06-16 19:25:07 +00:00
this.overrideLabel,
2023-06-17 01:25:49 +00:00
});
2024-05-15 21:20:45 +00:00
final CryptoCurrency coin;
2024-06-16 19:25:07 +00:00
final double min;
final double max;
final double pow;
2024-05-01 20:59:44 +00:00
final bool showWU;
2023-06-17 01:25:49 +00:00
final void Function(int) onSatVByteChanged;
2024-06-16 19:25:07 +00:00
final String? overrideLabel;
2023-06-17 01:25:49 +00:00
@override
State<FeeSlider> createState() => _FeeSliderState();
}
class _FeeSliderState extends State<FeeSlider> {
double sliderValue = 0;
2024-06-16 19:25:07 +00:00
late int rate;
@override
void initState() {
rate = widget.min.toInt();
super.initState();
}
2023-06-17 01:25:49 +00:00
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
2024-06-16 19:25:07 +00:00
widget.overrideLabel ?? (widget.showWU ? "sat/WU" : "sat/vByte"),
2023-06-17 01:25:49 +00:00
style: STextStyles.smallMed12(context),
),
Text(
"$rate",
style: STextStyles.smallMed12(context),
),
],
),
Slider(
value: sliderValue,
onChanged: (value) {
setState(() {
sliderValue = value;
2024-06-16 19:25:07 +00:00
final number = pow(
sliderValue * (widget.max - widget.min) + widget.min,
widget.pow,
).toDouble();
2024-05-15 21:20:45 +00:00
if (widget.coin is Dogecoin) {
rate = (number * 1000).toInt();
} else {
rate = number.toInt();
}
2023-06-17 01:25:49 +00:00
});
widget.onSatVByteChanged(rate);
},
),
],
);
}
}