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

View File

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

View File

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

View File

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