From b437a3f622217b3e3b67a92bdcb42c20a6a598b4 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 19 Oct 2023 14:02:42 +0300 Subject: [PATCH] minor fixes --- .../screens/contact/contact_list_page.dart | 22 ++----------------- .../desktop_wallet_selection_dropdown.dart | 18 +-------------- .../new_wallet/new_wallet_type_page.dart | 18 +-------------- lib/utils/icon_from_path.dart | 21 ++++++++++++++++++ 4 files changed, 25 insertions(+), 54 deletions(-) create mode 100644 lib/utils/icon_from_path.dart diff --git a/lib/src/screens/contact/contact_list_page.dart b/lib/src/screens/contact/contact_list_page.dart index f95a0a8ca..69a5df379 100644 --- a/lib/src/screens/contact/contact_list_page.dart +++ b/lib/src/screens/contact/contact_list_page.dart @@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/contact_base.dart'; import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/themes/extensions/cake_text_theme.dart'; import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart'; +import 'package:cake_wallet/utils/icon_from_path.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; @@ -113,7 +114,7 @@ class ContactListPage extends BasePage { } Widget generateRaw(BuildContext context, ContactBase contact) { - final currencyIcon = getIcon(contact.type.iconPath); + final currencyIcon = buildIconFromPath(contact.type.iconPath); return GestureDetector( onTap: () async { @@ -154,25 +155,6 @@ class ContactListPage extends BasePage { ); } - Widget getIcon(String? image) { - if (image != null && image.contains('svg')) { - return SvgPicture.asset( - image, - height: 24, - width: 24, - fit: BoxFit.contain, - ); - } else if (image != null && image.isNotEmpty) { - return Image.asset( - image, - height: 24, - width: 24, - ); - } else { - return const SizedBox(height: 24, width: 24); - } - } - Future showAlertDialog(BuildContext context) async { return await showPopUp( context: context, diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index 24cd7cf54..ef8924fe7 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -7,6 +7,7 @@ import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/dropdown_item_widget.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/themes/extensions/menu_theme.dart'; +import 'package:cake_wallet/utils/icon_from_path.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; @@ -135,23 +136,6 @@ class _DesktopWalletSelectionDropDownState extends State _loadWallet(WalletListItem wallet) async { widget._authService.authenticateAction(context, onAuthSuccess: (isAuthenticatedSuccessfully) async { diff --git a/lib/src/screens/new_wallet/new_wallet_type_page.dart b/lib/src/screens/new_wallet/new_wallet_type_page.dart index 667734d85..8d3eb5abe 100644 --- a/lib/src/screens/new_wallet/new_wallet_type_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_type_page.dart @@ -6,6 +6,7 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:cake_wallet/src/widgets/search_bar_widget.dart'; import 'package:cake_wallet/themes/extensions/cake_text_theme.dart'; import 'package:cake_wallet/themes/theme_base.dart'; +import 'package:cake_wallet/utils/icon_from_path.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/wallet_types.g.dart'; import 'package:cw_core/wallet_type.dart'; @@ -128,21 +129,4 @@ class WalletTypeFormState extends State { widget.onTypeSelected(context, selected!); } - - Widget buildIconFromPath(String? iconPath) { - if (iconPath != null && iconPath.contains('svg')) { - return SvgPicture.asset( - iconPath, - height: 24, - width: 24, - fit: BoxFit.contain, - ); - } else { - return Image.asset( - iconPath ?? '', - height: 24, - width: 24, - ); - } - } } diff --git a/lib/utils/icon_from_path.dart b/lib/utils/icon_from_path.dart new file mode 100644 index 000000000..70e2d6950 --- /dev/null +++ b/lib/utils/icon_from_path.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; + +Widget buildIconFromPath(String? iconPath, {double height = 24.0, double width = 24.0}) { + if (iconPath != null && iconPath.contains('svg')) { + return SvgPicture.asset( + iconPath, + height: height, + width: width, + fit: BoxFit.contain, + ); + } else if (iconPath != null && iconPath.isNotEmpty) { + return Image.asset( + iconPath, + height: height, + width: width, + ); + } else { + return SizedBox(height: height, width: width); + } +}