From 65b87ecae073723bed94b9bb7bb893abcb735662 Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Mon, 24 Oct 2022 21:06:03 +0200 Subject: [PATCH] Fix nullability of selected provider (#562) Remove un-necessary null operators --- lib/src/screens/buy/pre_order_page.dart | 21 +++++++++---------- .../screens/buy/widgets/buy_list_item.dart | 2 +- lib/view_model/buy/buy_view_model.dart | 3 +-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/src/screens/buy/pre_order_page.dart b/lib/src/screens/buy/pre_order_page.dart index 2b9bf94d2..00a64896f 100644 --- a/lib/src/screens/buy/pre_order_page.dart +++ b/lib/src/screens/buy/pre_order_page.dart @@ -80,7 +80,7 @@ class PreOrderPage extends BasePage { return KeyboardActions( config: KeyboardActionsConfig( keyboardActionsPlatform: KeyboardActionsPlatform.IOS, - keyboardBarColor: Theme.of(context).accentTextTheme!.bodyText1! + keyboardBarColor: Theme.of(context).accentTextTheme.bodyText1! .backgroundColor!, nextFocus: false, actions: [ @@ -102,10 +102,9 @@ class PreOrderPage extends BasePage { bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)), gradient: LinearGradient(colors: [ - Theme.of(context).primaryTextTheme!.subtitle1!.color!, + Theme.of(context).primaryTextTheme.subtitle1!.color!, Theme.of(context) - .primaryTextTheme! - .subtitle1! + .primaryTextTheme.subtitle1! .decorationColor!, ], begin: Alignment.topLeft, end: Alignment.bottomRight), ), @@ -161,11 +160,11 @@ class PreOrderPage extends BasePage { ), ), hintText: '0.00', - borderColor: Theme.of(context).primaryTextTheme!.bodyText1!.decorationColor!, + borderColor: Theme.of(context).primaryTextTheme.bodyText1!.decorationColor!, borderWidth: 0.5, textStyle: TextStyle(fontSize: 36, fontWeight: FontWeight.w500, color: Colors.white), placeholderTextStyle: TextStyle( - color: Theme.of(context).primaryTextTheme!.headline5!.decorationColor!, + color: Theme.of(context).primaryTextTheme.headline5!.decorationColor!, fontWeight: FontWeight.w500, fontSize: 36, ), @@ -180,7 +179,7 @@ class PreOrderPage extends BasePage { S.of(context).buy_with + ':', textAlign: TextAlign.center, style: TextStyle( - color: Theme.of(context).primaryTextTheme!.headline6!.color!, + color: Theme.of(context).primaryTextTheme.headline6!.color!, fontSize: 18, fontWeight: FontWeight.bold ), @@ -197,11 +196,11 @@ class PreOrderPage extends BasePage { double achAmount; int minAmount; - if (snapshot.hasData) { + if (snapshot.hasData && snapshot.data != null) { sourceAmount = snapshot.data!.sourceAmount; destAmount = snapshot.data!.destAmount; minAmount = snapshot.data!.minAmount; - achAmount = snapshot.data!.achSourceAmount!; + achAmount = snapshot.data!.achSourceAmount ?? 0; } else { sourceAmount = 0.0; destAmount = 0.0; @@ -215,7 +214,7 @@ class PreOrderPage extends BasePage { child: Observer(builder: (_) { return BuyListItem( selectedProvider: - buyViewModel.selectedProvider!, + buyViewModel.selectedProvider, provider: item.provider, sourceAmount: sourceAmount, sourceCurrency: buyViewModel.fiatCurrency, @@ -247,7 +246,7 @@ class PreOrderPage extends BasePage { ? S.of(context).buy : S.of(context).buy_with + ' ${buyViewModel.selectedProvider!.description.title}', - color: Theme.of(context).accentTextTheme!.bodyText1!.color!, + color: Theme.of(context).accentTextTheme.bodyText1!.color!, textColor: Colors.white, isLoading: buyViewModel.isRunning, isDisabled: (buyViewModel.selectedProvider == null) || diff --git a/lib/src/screens/buy/widgets/buy_list_item.dart b/lib/src/screens/buy/widgets/buy_list_item.dart index 8dc12ac58..fc8fea81d 100644 --- a/lib/src/screens/buy/widgets/buy_list_item.dart +++ b/lib/src/screens/buy/widgets/buy_list_item.dart @@ -18,7 +18,7 @@ class BuyListItem extends StatelessWidget { this.onTap }); - final BuyProvider selectedProvider; + final BuyProvider? selectedProvider; final BuyProvider provider; final double sourceAmount; final FiatCurrency sourceCurrency; diff --git a/lib/view_model/buy/buy_view_model.dart b/lib/view_model/buy/buy_view_model.dart index 2baa1447b..080caa3ad 100644 --- a/lib/view_model/buy/buy_view_model.dart +++ b/lib/view_model/buy/buy_view_model.dart @@ -6,7 +6,6 @@ import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/view_model/buy/buy_item.dart'; -import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/store/dashboard/orders_store.dart'; @@ -103,7 +102,7 @@ abstract class BuyViewModelBase with Store { print(e.toString()); } - if (isMoonPayEnabled ?? false) { + if (isMoonPayEnabled) { _providerList.add(MoonPayBuyProvider(wallet: wallet)); }