stack_wallet/lib/widgets/fee_slider.dart

67 lines
1.6 KiB
Dart
Raw Normal View History

2023-06-17 01:25:49 +00:00
import 'dart:math';
import 'package:flutter/material.dart';
import '../utilities/text_styles.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
2023-06-17 01:25:49 +00:00
class FeeSlider extends StatefulWidget {
const FeeSlider({
super.key,
required this.onSatVByteChanged,
required this.coin,
2024-05-01 20:59:44 +00:00
this.showWU = false,
2023-06-17 01:25:49 +00:00
});
2024-05-15 21:20:45 +00:00
final CryptoCurrency coin;
2024-05-01 20:59:44 +00:00
final bool showWU;
2023-06-17 01:25:49 +00:00
final void Function(int) onSatVByteChanged;
@override
State<FeeSlider> createState() => _FeeSliderState();
}
class _FeeSliderState extends State<FeeSlider> {
static const double min = 1;
static const double max = 4;
2023-06-17 01:25:49 +00:00
double sliderValue = 0;
int rate = min.toInt();
2023-06-17 01:25:49 +00:00
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
2024-05-01 20:59:44 +00:00
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;
final number = pow(sliderValue * (max - min) + min, 4).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);
},
),
],
);
}
}