Fix nullability of selected provider (#562)

Remove un-necessary null operators

Omar Hatem committed Oct 24, 2022 at 21:06 UTC 65b87ecae073723bed94b9bb7bb893abcb735662
3 files changed +12 -14
lib/src/screens/buy/pre_order_page.dart
+10 -11
@@ -80,7 +80,7 @@ class PreOrderPage extends BasePage {
80 return KeyboardActions(
81 config: KeyboardActionsConfig(
82 keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
83 - keyboardBarColor: Theme.of(context).accentTextTheme!.bodyText1!
83 + keyboardBarColor: Theme.of(context).accentTextTheme.bodyText1!
84 .backgroundColor!,
85 nextFocus: false,
86 actions: [
@@ -102,10 +102,9 @@ class PreOrderPage extends BasePage {
102 bottomLeft: Radius.circular(24),
103 bottomRight: Radius.circular(24)),
104 gradient: LinearGradient(colors: [
105 - Theme.of(context).primaryTextTheme!.subtitle1!.color!,
105 + Theme.of(context).primaryTextTheme.subtitle1!.color!,
106 Theme.of(context)
107 - .primaryTextTheme!
108 - .subtitle1!
107 + .primaryTextTheme.subtitle1!
108 .decorationColor!,
109 ], begin: Alignment.topLeft, end: Alignment.bottomRight),
110 ),
@@ -161,11 +160,11 @@ class PreOrderPage extends BasePage {
160 ),
161 ),
162 hintText: '0.00',
164 - borderColor: Theme.of(context).primaryTextTheme!.bodyText1!.decorationColor!,
163 + borderColor: Theme.of(context).primaryTextTheme.bodyText1!.decorationColor!,
164 borderWidth: 0.5,
165 textStyle: TextStyle(fontSize: 36, fontWeight: FontWeight.w500, color: Colors.white),
166 placeholderTextStyle: TextStyle(
168 - color: Theme.of(context).primaryTextTheme!.headline5!.decorationColor!,
167 + color: Theme.of(context).primaryTextTheme.headline5!.decorationColor!,
168 fontWeight: FontWeight.w500,
169 fontSize: 36,
170 ),
@@ -180,7 +179,7 @@ class PreOrderPage extends BasePage {
179 S.of(context).buy_with + ':',
180 textAlign: TextAlign.center,
181 style: TextStyle(
183 - color: Theme.of(context).primaryTextTheme!.headline6!.color!,
182 + color: Theme.of(context).primaryTextTheme.headline6!.color!,
183 fontSize: 18,
184 fontWeight: FontWeight.bold
185 ),
@@ -197,11 +196,11 @@ class PreOrderPage extends BasePage {
196 double achAmount;
197 int minAmount;
198
200 - if (snapshot.hasData) {
199 + if (snapshot.hasData && snapshot.data != null) {
200 sourceAmount = snapshot.data!.sourceAmount;
201 destAmount = snapshot.data!.destAmount;
202 minAmount = snapshot.data!.minAmount;
204 - achAmount = snapshot.data!.achSourceAmount!;
203 + achAmount = snapshot.data!.achSourceAmount ?? 0;
204 } else {
205 sourceAmount = 0.0;
206 destAmount = 0.0;
@@ -215,7 +214,7 @@ class PreOrderPage extends BasePage {
214 child: Observer(builder: (_) {
215 return BuyListItem(
216 selectedProvider:
218 - buyViewModel.selectedProvider!,
217 + buyViewModel.selectedProvider,
218 provider: item.provider,
219 sourceAmount: sourceAmount,
220 sourceCurrency: buyViewModel.fiatCurrency,
@@ -247,7 +246,7 @@ class PreOrderPage extends BasePage {
246 ? S.of(context).buy
247 : S.of(context).buy_with +
248 ' ${buyViewModel.selectedProvider!.description.title}',
250 - color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
249 + color: Theme.of(context).accentTextTheme.bodyText1!.color!,
250 textColor: Colors.white,
251 isLoading: buyViewModel.isRunning,
252 isDisabled: (buyViewModel.selectedProvider == null) ||
lib/src/screens/buy/widgets/buy_list_item.dart
+1 -1
@@ -18,7 +18,7 @@ class BuyListItem extends StatelessWidget {
18 this.onTap
19 });
20
21 - final BuyProvider selectedProvider;
21 + final BuyProvider? selectedProvider;
22 final BuyProvider provider;
23 final double sourceAmount;
24 final FiatCurrency sourceCurrency;
lib/view_model/buy/buy_view_model.dart
+1 -2
@@ -6,7 +6,6 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
6 import 'package:cw_core/wallet_type.dart';
7 import 'package:cake_wallet/store/settings_store.dart';
8 import 'package:cake_wallet/view_model/buy/buy_item.dart';
9 -import 'package:flutter/foundation.dart';
9 import 'package:hive/hive.dart';
10 import 'package:cake_wallet/buy/order.dart';
11 import 'package:cake_wallet/store/dashboard/orders_store.dart';
@@ -103,7 +102,7 @@ abstract class BuyViewModelBase with Store {
102 print(e.toString());
103 }
104
106 - if (isMoonPayEnabled ?? false) {
105 + if (isMoonPayEnabled) {
106 _providerList.add(MoonPayBuyProvider(wallet: wallet));
107 }
108