Files
GitJournal/lib/widgets/purchase_slider.dart
Vishesh Handa 28d53242d8 Move away from RevenueCat
The iOS updates keep getting rejected, and I think it's because
RevenueCat is taking too long to respond. Additionally, revenueCat
doesn't really give us anything useful as its receipt validation isn't
perfect, and I've had to roll my own.

Plus from a privacy point of view, this is better as we are no longer
talking to any third party service.

This has so far only been tested on iOS
2020-07-26 12:20:09 +02:00

63 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:equatable/equatable.dart';
class PaymentInfo extends Equatable {
final double value;
final String text;
final String id;
PaymentInfo({@required this.id, @required this.value, @required this.text});
@override
List<Object> get props => [value, text, id];
}
typedef PaymentSliderChanged = Function(PaymentInfo);
class PurchaseSlider extends StatelessWidget {
final List<PaymentInfo> values;
final PaymentInfo selectedValue;
final PaymentSliderChanged onChanged;
PurchaseSlider({
@required this.values,
@required this.selectedValue,
@required this.onChanged,
}) {
values.sort((a, b) => a.value.compareTo(b.value));
}
@override
Widget build(BuildContext context) {
return Slider(
min: values.first.value,
max: values.last.value + 0.50,
value: selectedValue.value,
onChanged: (double val) {
int i = -1;
for (i = 1; i < values.length; i++) {
var prev = values[i - 1].value;
var cur = values[i].value;
if (prev < val && val <= cur) {
i--;
break;
}
}
if (val == values.first.value) {
i = 0;
} else if (val >= values.last.value) {
i = values.length - 1;
}
if (i != -1) {
onChanged(values[i]);
}
},
label: selectedValue.text,
divisions: values.length,
);
}
}