Cw 188 fix grey screen (#537)

* Fix late initialization exception when using late with Mobx Fix index out of range exception in picker * Add haven account list class to configure file to be generated in haven.dart

Omar Hatem committed Oct 17, 2022 at 23:01 UTC da6fd9a9ffbac61a8c4074391e10109bed2f9085
3 files changed +32 -31
lib/src/screens/settings/widgets/settings_picker_cell.dart
+4 -1
@@ -53,7 +53,10 @@ class SettingsPickerCell<ItemType extends Object> extends StandardListRow {
53 displayItem?.call(selectedItem) ?? selectedItem.toString(),
54 textAlign: TextAlign.right,
55 style: TextStyle(
56 - fontSize: 14.0, fontWeight: FontWeight.w500, color: Theme.of(context).primaryTextTheme!.overline!.color!),
56 + fontSize: 14.0,
57 + fontWeight: FontWeight.w500,
58 + color: Theme.of(context).primaryTextTheme.overline?.color,
59 + ),
60 );
61 }
62 }
lib/src/widgets/picker.dart
+23 -24
@@ -1,3 +1,5 @@
1 +// ignore_for_file: deprecated_member_use
2 +
3 import 'package:flutter/material.dart';
4 import 'package:cake_wallet/src/widgets/alert_background.dart';
5 import 'package:cake_wallet/src/widgets/alert_close_button.dart';
@@ -34,11 +36,11 @@ class Picker<Item extends Object> extends StatefulWidget {
36 final bool Function(Item, String)? matchingCriteria;
37
38 @override
37 - PickerState createState() => PickerState<Item>(items, images, onItemSelected);
39 + _PickerState<Item> createState() => _PickerState<Item>(items, images, onItemSelected);
40 }
41
40 -class PickerState<Item> extends State<Picker> {
41 - PickerState(this.items, this.images, this.onItemSelected);
42 +class _PickerState<Item> extends State<Picker> {
43 + _PickerState(this.items, this.images, this.onItemSelected);
44
45 final Function(Item) onItemSelected;
46 List<Item> items;
@@ -94,7 +96,7 @@ class PickerState<Item> extends State<Picker> {
96 child: ClipRRect(
97 borderRadius: BorderRadius.all(Radius.circular(30)),
98 child: Container(
97 - color: Theme.of(context).accentTextTheme!.headline6!.color!,
99 + color: Theme.of(context).accentTextTheme.headline6!.color!,
100 child: ConstrainedBox(
101 constraints: BoxConstraints(
102 maxHeight: MediaQuery.of(context).size.height * 0.65,
@@ -107,12 +109,12 @@ class PickerState<Item> extends State<Picker> {
109 padding: const EdgeInsets.all(16),
110 child: TextFormField(
111 controller: searchController,
110 - style: TextStyle(color: Theme.of(context).primaryTextTheme!.headline6!.color!),
112 + style: TextStyle(color: Theme.of(context).primaryTextTheme.headline6!.color!),
113 decoration: InputDecoration(
114 hintText: widget.hintText,
115 prefixIcon: Image.asset("assets/images/search_icon.png"),
116 filled: true,
115 - fillColor: Theme.of(context).accentTextTheme!.headline3!.color!,
117 + fillColor: Theme.of(context).accentTextTheme.headline3!.color!,
118 alignLabelWithHint: false,
119 contentPadding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
120 enabledBorder: OutlineInputBorder(
@@ -129,7 +131,7 @@ class PickerState<Item> extends State<Picker> {
131 ),
132 ),
133 Divider(
132 - color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!,
134 + color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!,
135 height: 1,
136 ),
137 if (widget.selectedAtIndex != -1) buildSelectedItem(),
@@ -137,7 +139,7 @@ class PickerState<Item> extends State<Picker> {
139 child: Stack(
140 alignment: Alignment.center,
141 children: <Widget>[
140 - (items?.length ?? 0) > 3 ? Scrollbar(
142 + items.length > 3 ? Scrollbar(
143 controller: controller,
144 child: itemsList(),
145 ) : itemsList(),
@@ -154,7 +156,7 @@ class PickerState<Item> extends State<Picker> {
156 fontWeight: FontWeight.w500,
157 fontFamily: 'Lato',
158 decoration: TextDecoration.none,
157 - color: Theme.of(context).primaryTextTheme!.headline6!.color!,
159 + color: Theme.of(context).primaryTextTheme.headline6!.color!,
160 ),
161 ),
162 )
@@ -178,13 +180,13 @@ class PickerState<Item> extends State<Picker> {
180
181 Widget itemsList() {
182 return Container(
181 - color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!,
183 + color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!,
184 child: widget.isGridView
185 ? GridView.builder(
186 padding: EdgeInsets.zero,
187 controller: controller,
188 shrinkWrap: true,
187 - itemCount: items == null || items.isEmpty ? 0 : items.length,
189 + itemCount: items.isEmpty ? 0 : items.length,
190 gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
191 crossAxisCount: 2,
192 crossAxisSpacing: 2,
@@ -198,11 +200,11 @@ class PickerState<Item> extends State<Picker> {
200 shrinkWrap: true,
201 separatorBuilder: (context, index) => widget.isSeparated
202 ? Divider(
201 - color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!,
203 + color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!,
204 height: 1,
205 )
206 : const SizedBox(),
205 - itemCount: items == null || items.isEmpty ? 0 : items.length,
207 + itemCount: items.isEmpty ? 0 : items.length,
208 itemBuilder: (context, index) => buildItem(index),
209 ),
210 );
@@ -215,19 +217,16 @@ class PickerState<Item> extends State<Picker> {
217 }
218
219 final item = items[index];
218 - final image = images != null ? images[index] : null;
220 + final image = images.isNotEmpty ? images[index] : null;
221
222 return GestureDetector(
223 onTap: () {
222 - if (onItemSelected == null) {
223 - return;
224 - }
224 Navigator.of(context).pop();
225 onItemSelected(item);
226 },
227 child: Container(
228 height: 55,
230 - color: Theme.of(context).accentTextTheme!.headline6!.color!,
229 + color: Theme.of(context).accentTextTheme.headline6!.color!,
230 padding: EdgeInsets.only(left: 24, right: 24),
231 child: Row(
232 mainAxisSize: MainAxisSize.max,
@@ -239,13 +238,13 @@ class PickerState<Item> extends State<Picker> {
238 child: Padding(
239 padding: EdgeInsets.only(left: image != null ? 12 : 0),
240 child: Text(
242 - // What a hack (item as) ?
241 + // What a hack (item as) ?
242 widget.displayItem?.call(item as Object) ?? item.toString(),
243 style: TextStyle(
244 fontSize: 14,
245 fontFamily: 'Lato',
246 fontWeight: FontWeight.w600,
248 - color: Theme.of(context).primaryTextTheme!.headline6!.color!,
247 + color: Theme.of(context).primaryTextTheme.headline6!.color!,
248 decoration: TextDecoration.none,
249 ),
250 ),
@@ -259,11 +258,11 @@ class PickerState<Item> extends State<Picker> {
258
259 Widget buildSelectedItem() {
260 final item = widget.items[widget.selectedAtIndex];
262 - final image = images != null ? widget.images[widget.selectedAtIndex] : null;
261 + final image = images.isNotEmpty ? widget.images[widget.selectedAtIndex] : null;
262
263 return Container(
264 height: 55,
266 - color: Theme.of(context).accentTextTheme!.headline6!.color!,
265 + color: Theme.of(context).accentTextTheme.headline6!.color!,
266 padding: EdgeInsets.only(left: 24, right: 24),
267 child: Row(
268 mainAxisSize: MainAxisSize.max,
@@ -280,13 +279,13 @@ class PickerState<Item> extends State<Picker> {
279 fontSize: 16,
280 fontFamily: 'Lato',
281 fontWeight: FontWeight.w700,
283 - color: Theme.of(context).primaryTextTheme!.headline6!.color!,
282 + color: Theme.of(context).primaryTextTheme.headline6!.color!,
283 decoration: TextDecoration.none,
284 ),
285 ),
286 ),
287 ),
289 - Icon(Icons.check_circle, color: Theme.of(context).accentTextTheme!.bodyText1!.color!),
288 + Icon(Icons.check_circle, color: Theme.of(context).accentTextTheme.bodyText1!.color!),
289 ],
290 ),
291 );
lib/view_model/buy/buy_amount_view_model.dart
+5 -6
@@ -9,22 +9,21 @@ class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
9
10 abstract class BuyAmountViewModelBase with Store {
11 BuyAmountViewModelBase()
12 - : amount = '' {
12 + : amount = '',
13 + fiatCurrency = FiatCurrency.usd {
14 int selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
15 .indexOf(getIt.get<SettingsStore>().fiatCurrency);
16
16 - if (selectedIndex == -1) {
17 - selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
18 - .indexOf(FiatCurrency.usd);
17 + if (selectedIndex != -1) {
18 + fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
19 }
20 - fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
20 }
21
22 @observable
23 String amount;
24
25 @observable
27 - late FiatCurrency fiatCurrency;
26 + FiatCurrency fiatCurrency;
27
28 @computed
29 double get doubleAmount {