1
0
mirror of https://github.com/GitJournal/GitJournal.git synced 2025-07-11 04:54:20 +08:00

PurchaseSlider: Fixx null access

Fixes APP-17G
This commit is contained in:
Vishesh Handa
2021-06-30 10:55:08 +02:00
parent ed44cf8652
commit 75ee598fac
3 changed files with 14 additions and 10 deletions

@ -128,8 +128,8 @@ class PurchaseManager {
// FIXME: What if the sotre cannot be reached?
var response = await _instance!.con.queryProductDetails(skus);
response.productDetails.sort((a, b) {
var pa = PaymentInfo.fromProductDetail(a)!;
var pb = PaymentInfo.fromProductDetail(b)!;
var pa = PaymentInfo.fromProductDetail(a);
var pb = PaymentInfo.fromProductDetail(b);
return pa.value.compareTo(pb.value);
});

@ -15,7 +15,7 @@ class PaymentInfo extends Equatable {
@override
List<Object> get props => [value, text, id];
static PaymentInfo? fromProductDetail(ProductDetails pd) {
static PaymentInfo fromProductDetail(ProductDetails pd) {
double value = -1;
if (pd.skProduct != null) {
value = double.parse(pd.skProduct!.price);
@ -34,8 +34,8 @@ class PaymentInfo extends Equatable {
typedef PaymentSliderChanged = void Function(PaymentInfo);
class PurchaseSlider extends StatelessWidget {
final List<PaymentInfo?> values;
final PaymentInfo? selectedValue;
final List<PaymentInfo> values;
final PaymentInfo selectedValue;
final PaymentSliderChanged onChanged;
PurchaseSlider({
@ -43,7 +43,7 @@ class PurchaseSlider extends StatelessWidget {
required this.selectedValue,
required this.onChanged,
}) {
values.sort((a, b) => a!.value.compareTo(b!.value));
values.sort((a, b) => a.value.compareTo(b.value));
}
@override
@ -63,8 +63,8 @@ class PurchaseSlider extends StatelessWidget {
}
class ShapePainter extends CustomPainter {
final List<PaymentInfo?> values;
final PaymentInfo? selectedValue;
final List<PaymentInfo> values;
final PaymentInfo selectedValue;
final Color color;
ShapePainter({
@ -91,8 +91,8 @@ class ShapePainter extends CustomPainter {
..strokeCap = StrokeCap.round
..style = PaintingStyle.fill;
var diff = (values.last!.value - values.first!.value);
var w = (size.width / diff) * (selectedValue!.value - values.first!.value);
var diff = (values.last.value - values.first.value);
var w = (size.width / diff) * (selectedValue.value - values.first.value);
var angle = atan(size.height / size.width);
var h = w * tan(angle);

@ -185,6 +185,10 @@ class _PurchaseWidgetState extends State<PurchaseWidget> {
}
Widget buildBody(BuildContext context) {
if (_products == null || _products!.isEmpty) {
return const Icon(Icons.error, size: 64);
}
var slider = PurchaseSlider(
values: _products!.map(PaymentInfo.fromProductDetail).toList(),
selectedValue: PaymentInfo.fromProductDetail(_selectedProduct!),