From 6bbe95fa5ebb68c8e77a9d202f8e9c6d173c43f7 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 6 Jul 2023 03:00:01 +0300 Subject: [PATCH] - Fix scroll issue - Add ERC20 tokens placeholder image in picker --- .../screens/dashboard/home_settings_page.dart | 104 +++++++++--------- lib/src/widgets/picker.dart | 99 +++++++++-------- 2 files changed, 105 insertions(+), 98 deletions(-) diff --git a/lib/src/screens/dashboard/home_settings_page.dart b/lib/src/screens/dashboard/home_settings_page.dart index 465820455..c6b005bde 100644 --- a/lib/src/screens/dashboard/home_settings_page.dart +++ b/lib/src/screens/dashboard/home_settings_page.dart @@ -96,61 +96,65 @@ class HomeSettingsPage extends BasePage { ), ], ), - Observer( - builder: (_) => ListView.builder( - itemCount: _homeSettingsViewModel.tokens.length, - shrinkWrap: true, - itemBuilder: (context, index) { - return Container( - margin: EdgeInsets.only(top: 16, left: 16, right: 16), - child: Observer( - builder: (_) { - final token = _homeSettingsViewModel.tokens.elementAt(index); + Padding( + padding: const EdgeInsets.only(bottom: 16, left: 16, right: 16), + child: Observer( + builder: (_) => ListView.builder( + itemCount: _homeSettingsViewModel.tokens.length, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return Container( + margin: EdgeInsets.only(top: 16), + child: Observer( + builder: (_) { + final token = _homeSettingsViewModel.tokens.elementAt(index); - return SettingsSwitcherCell( - title: "${token.name} " - "(${token.symbol})", - value: token.enabled, - onValueChange: (_, bool value) { - _homeSettingsViewModel.changeTokenAvailability(token, value); - }, - onTap: (_) { - Navigator.pushNamed(context, Routes.editToken, arguments: { - 'homeSettingsViewModel': _homeSettingsViewModel, - 'token': token, - }); - }, - leading: token.iconPath != null - ? Container( - child: Image.asset( - token.iconPath!, + return SettingsSwitcherCell( + title: "${token.name} " + "(${token.symbol})", + value: token.enabled, + onValueChange: (_, bool value) { + _homeSettingsViewModel.changeTokenAvailability(token, value); + }, + onTap: (_) { + Navigator.pushNamed(context, Routes.editToken, arguments: { + 'homeSettingsViewModel': _homeSettingsViewModel, + 'token': token, + }); + }, + leading: token.iconPath != null + ? Container( + child: Image.asset( + token.iconPath!, + height: 30.0, + width: 30.0, + ), + ) + : Container( height: 30.0, width: 30.0, - ), - ) - : Container( - height: 30.0, - width: 30.0, - child: Center( - child: Text( - token.symbol.substring(0, min(token.symbol.length, 2)), - style: TextStyle(fontSize: 11), + child: Center( + child: Text( + token.symbol.substring(0, min(token.symbol.length, 2)), + style: TextStyle(fontSize: 11), + ), + ), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.grey.shade400, ), ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.grey.shade400, - ), - ), - decoration: BoxDecoration( - color: Theme.of(context).accentTextTheme.bodySmall!.color!, - borderRadius: BorderRadius.circular(30), - ), - ); - }, - ), - ); - }, + decoration: BoxDecoration( + color: Theme.of(context).accentTextTheme.bodySmall!.color!, + borderRadius: BorderRadius.circular(30), + ), + ); + }, + ), + ); + }, + ), ), ), ], diff --git a/lib/src/widgets/picker.dart b/lib/src/widgets/picker.dart index 7be1d611a..4f3873a27 100644 --- a/lib/src/widgets/picker.dart +++ b/lib/src/widgets/picker.dart @@ -1,5 +1,7 @@ // ignore_for_file: deprecated_member_use +import 'dart:math'; + import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:flutter/material.dart'; import 'package:cw_core/currency.dart'; @@ -144,8 +146,7 @@ class _PickerState extends State> { borderRadius: BorderRadius.all(Radius.circular(30)), child: Container( color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .color!, child: ConstrainedBox( constraints: BoxConstraints( @@ -162,8 +163,7 @@ class _PickerState extends State> { controller: searchController, style: TextStyle( color: Theme.of(context) - .primaryTextTheme! - .titleLarge! + .primaryTextTheme.titleLarge! .color!), decoration: InputDecoration( hintText: widget.hintText, @@ -171,8 +171,7 @@ class _PickerState extends State> { Image.asset("assets/images/search_icon.png"), filled: true, fillColor: Theme.of(context) - .accentTextTheme! - .displaySmall! + .accentTextTheme.displaySmall! .color!, alignLabelWithHint: false, contentPadding: const EdgeInsets.symmetric( @@ -192,8 +191,7 @@ class _PickerState extends State> { ), Divider( color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .backgroundColor!, height: 1, ), @@ -223,8 +221,7 @@ class _PickerState extends State> { fontFamily: 'Lato', decoration: TextDecoration.none, color: Theme.of(context) - .primaryTextTheme! - .titleLarge! + .primaryTextTheme.titleLarge! .color!, ), ), @@ -246,8 +243,7 @@ class _PickerState extends State> { Widget itemsList() { return Container( color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .backgroundColor!, child: widget.isGridView ? GridView.builder( @@ -269,8 +265,7 @@ class _PickerState extends State> { separatorBuilder: (context, index) => widget.isSeparated ? Divider( color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .backgroundColor!, height: 1, ) @@ -283,15 +278,9 @@ class _PickerState extends State> { Widget buildItem(int index) { final item = filteredItems[index]; - final tag = item is Currency ? item.tag : null; - final icon = item is Currency && item.iconPath != null - ? Image.asset( - item.iconPath!, - height: 20.0, - width: 20.0, - ) - : null; + final tag = item is Currency ? item.tag : null; + final icon = _getItemIcon(item); final image = images.isNotEmpty ? filteredImages[index] : icon; @@ -303,8 +292,7 @@ class _PickerState extends State> { child: Container( height: 55, color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .color!, padding: EdgeInsets.symmetric(horizontal: 24), child: Row( @@ -327,8 +315,7 @@ class _PickerState extends State> { fontFamily: 'Lato', fontWeight: FontWeight.w600, color: Theme.of(context) - .primaryTextTheme! - .titleLarge! + .primaryTextTheme.titleLarge! .color!, decoration: TextDecoration.none, ), @@ -347,8 +334,7 @@ class _PickerState extends State> { fontSize: 7.0, fontFamily: 'Lato', color: Theme.of(context) - .textTheme! - .bodyMedium! + .textTheme.bodyMedium! .color!), ), ), @@ -356,8 +342,7 @@ class _PickerState extends State> { borderRadius: BorderRadius.circular(6.0), //border: Border.all(color: ), color: Theme.of(context) - .textTheme! - .bodyMedium! + .textTheme.bodyMedium! .decorationColor!, ), ), @@ -374,15 +359,9 @@ class _PickerState extends State> { Widget buildSelectedItem(int index) { final item = items[index]; - final tag = item is Currency ? item.tag : null; - final icon = item is Currency && item.iconPath != null - ? Image.asset( - item.iconPath!, - height: 20.0, - width: 20.0, - ) - : null; + final tag = item is Currency ? item.tag : null; + final icon = _getItemIcon(item); final image = images.isNotEmpty ? images[index] : icon; @@ -393,8 +372,7 @@ class _PickerState extends State> { child: Container( height: 55, color: Theme.of(context) - .accentTextTheme! - .titleLarge! + .accentTextTheme.titleLarge! .color!, padding: EdgeInsets.symmetric(horizontal: 24), child: Row( @@ -417,8 +395,7 @@ class _PickerState extends State> { fontFamily: 'Lato', fontWeight: FontWeight.w700, color: Theme.of(context) - .primaryTextTheme! - .titleLarge! + .primaryTextTheme.titleLarge! .color!, decoration: TextDecoration.none, ), @@ -437,8 +414,7 @@ class _PickerState extends State> { fontSize: 7.0, fontFamily: 'Lato', color: Theme.of(context) - .textTheme! - .bodyMedium! + .textTheme.bodyMedium! .color!), ), ), @@ -446,8 +422,7 @@ class _PickerState extends State> { borderRadius: BorderRadius.circular(6.0), //border: Border.all(color: ), color: Theme.of(context) - .textTheme! - .bodyMedium! + .textTheme.bodyMedium! .decorationColor!, ), ), @@ -458,12 +433,40 @@ class _PickerState extends State> { ), Icon(Icons.check_circle, color: Theme.of(context) - .accentTextTheme! - .bodyLarge! + .accentTextTheme.bodyLarge! .color!), ], ), ), ); } + + Widget? _getItemIcon(Item item) { + if (item is Currency) { + if (item.iconPath != null) { + return Image.asset( + item.iconPath!, + height: 20.0, + width: 20.0, + ); + } else { + return Container( + height: 20.0, + width: 20.0, + child: Center( + child: Text( + item.name.substring(0, min(item.name.length, 2)).toUpperCase(), + style: TextStyle(fontSize: 11), + ), + ), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.grey.shade400, + ), + ); + } + } + + return null; + } }