From 76b7948765faccb2a8297af04a7f796bfd70002c Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 15:10:44 +0330 Subject: [PATCH 1/6] fix: New dapps sizes --- .../responsive_layout/card_item.dart | 37 +++---------------- .../responsive_layout/dapp_card_layout.dart | 1 + .../responsive_layout/new_dapp_card.dart | 2 +- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/lib/features/dapps/presentation/responsive_layout/card_item.dart b/lib/features/dapps/presentation/responsive_layout/card_item.dart index c90e48dd..138cdc50 100644 --- a/lib/features/dapps/presentation/responsive_layout/card_item.dart +++ b/lib/features/dapps/presentation/responsive_layout/card_item.dart @@ -1,39 +1,12 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; + class CardCrossAxisCount { - static const int mobile = 4; - static const int tablet = 5; + static const int mobile = 6; + static const int tablet = 7; } class CardMainAxisCount { - static const int mobile = 3; - static const int tablet = 4; + static const int mobile = 4; + static const int tablet = 5; } - -class CardSizes { - static Widget large({required Widget child}) { - return StaggeredGridTile.count( - crossAxisCellCount: 4, - mainAxisCellCount: 2, - child: child, - ); - } - - static Widget medium({required Widget child}) { - return StaggeredGridTile.count( - crossAxisCellCount: 2, - mainAxisCellCount: 2, - child: child, - ); - } - - static Widget small({required Widget child}) { - return StaggeredGridTile.count( - crossAxisCellCount: 1, - mainAxisCellCount: 1, - child: child, - ); - } -} diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart index c2b20a32..4d512bde 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart @@ -82,6 +82,7 @@ class DappCardLayout extends HookConsumerWidget { }, ), ), + const SizedBox(height: Sizes.spaceXLarge,), DAppIndicator( total: pages, selectedIndex: state.pageIndex, diff --git a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart b/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart index 2bbadcc3..9b918e7b 100644 --- a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart +++ b/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart @@ -53,7 +53,7 @@ class NewDAppCard extends HookConsumerWidget { final name = dapp is Bookmark ? (dapp as Bookmark).title : dapp.app!.name!; final imageSize = width * (ratioFactor ?? - (mainAxisCount == CardMainAxisCount.mobile ? 0.3 : 0.2)); + (mainAxisCount == CardMainAxisCount.mobile ? 0.2 : 0.1)); return GestureDetector( onTap: () { if (animated) { From 34b8dbb0efe303bbfc8019419ec1330071b37df6 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 15:17:19 +0330 Subject: [PATCH 2/6] refactor: Remove unnecessary package --- .../responsive_layout/card_item.dart | 5 +- .../responsive_layout/dapp_card.dart | 91 ------------------- .../responsive_layout/dapp_card_layout.dart | 8 +- .../responsive_layout/dapp_loading.dart | 1 - .../responsive_layout/new_dapp_card.dart | 4 +- pubspec.lock | 8 -- pubspec.yaml | 1 - 7 files changed, 8 insertions(+), 110 deletions(-) delete mode 100644 lib/features/dapps/presentation/responsive_layout/dapp_card.dart diff --git a/lib/features/dapps/presentation/responsive_layout/card_item.dart b/lib/features/dapps/presentation/responsive_layout/card_item.dart index 138cdc50..6478efea 100644 --- a/lib/features/dapps/presentation/responsive_layout/card_item.dart +++ b/lib/features/dapps/presentation/responsive_layout/card_item.dart @@ -1,12 +1,9 @@ - - class CardCrossAxisCount { static const int mobile = 6; static const int tablet = 7; } class CardMainAxisCount { - static const int mobile = 4; + static const int mobile = 3; static const int tablet = 5; } - diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card.dart deleted file mode 100644 index bc5c324c..00000000 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:cached_network_image/cached_network_image.dart'; -import 'package:flutter/material.dart'; -import 'package:mxc_logic/mxc_logic.dart'; -import 'package:mxc_ui/mxc_ui.dart'; - -class DappCard extends StatelessWidget { - const DappCard({ - super.key, - required this.dapp, - this.isEditMode = false, - this.onTap, - this.onLongPress, - this.onRemoveTap, - }); - - final Dapp dapp; - final bool isEditMode; - final VoidCallback? onTap; - final VoidCallback? onLongPress; - final Function(Bookmark?)? onRemoveTap; - - Widget cardBox(BuildContext context) { - final bookmark = dapp is Bookmark ? dapp as Bookmark : null; - if (bookmark != null) { - return Container( - padding: const EdgeInsets.all(2), - width: double.infinity, - height: double.infinity, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: const BorderRadius.all( - Radius.circular(8), - ), - color: ColorsTheme.of(context).cardBackground, - ), - child: Text( - bookmark.title, - style: FontTheme.of(context).subtitle2().copyWith( - color: ColorsTheme.of(context).textSecondary, - ), - overflow: TextOverflow.ellipsis, - ), - ); - } else { - final icons = dapp.reviewApi!.icons!; - final image = icons.islarge != null && icons.islarge! - ? icons.iconLarge - : icons.iconSmall; - - return ClipRRect( - borderRadius: BorderRadius.circular(22), - child: image!.contains('https') - ? CachedNetworkImage( - imageUrl: image, - fit: BoxFit.cover, - ) - : Image.asset(image)); - } - } - - @override - Widget build(BuildContext context) { - return GestureDetector( - onTap: onTap, - onLongPress: onLongPress, - child: Stack( - children: [ - Padding( - padding: const EdgeInsets.all(4), - child: Center( - child: cardBox(context), - ), - ), - if (isEditMode) - Positioned( - top: -2, - left: -2, - child: InkWell( - onTap: onRemoveTap != null - ? () => onRemoveTap!(dapp as Bookmark) - : null, - child: const Icon( - Icons.remove_circle_rounded, - ), - ), - ), - ], - ), - ); - } -} diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart index 4d512bde..6346cccb 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart @@ -82,7 +82,9 @@ class DappCardLayout extends HookConsumerWidget { }, ), ), - const SizedBox(height: Sizes.spaceXLarge,), + const SizedBox( + height: Sizes.spaceXLarge, + ), DAppIndicator( total: pages, selectedIndex: state.pageIndex, @@ -100,7 +102,7 @@ List getList(List dapps, DAppsPagePresenter actions, final item = dapps[i]; final isBookMark = item is Bookmark; final dappCard = isBookMark - ? NewDAppCard( + ? DAppCard( index: i, width: itemWidth, dapp: item, @@ -108,7 +110,7 @@ List getList(List dapps, DAppsPagePresenter actions, onTap: state.isEditMode ? null : () => actions.openDapp(item.url), mainAxisCount: mainAxisCount, ) - : NewDAppCard( + : DAppCard( index: i, width: itemWidth, dapp: item, diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_loading.dart b/lib/features/dapps/presentation/responsive_layout/dapp_loading.dart index 724cda7e..99db8634 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_loading.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_loading.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:mxc_ui/mxc_ui.dart'; import 'package:shimmer/shimmer.dart'; diff --git a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart b/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart index 9b918e7b..a5028298 100644 --- a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart +++ b/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart @@ -16,14 +16,14 @@ import 'package:reorderable_grid_view/reorderable_grid_view.dart'; import '../dapps_presenter.dart'; import 'shatter_widget.dart'; -class NewDAppCard extends HookConsumerWidget { +class DAppCard extends HookConsumerWidget { final Dapp dapp; final int index; final double width; final bool isEditMode; final VoidCallback? onTap; final int mainAxisCount; - const NewDAppCard({ + const DAppCard({ super.key, required this.index, required this.width, diff --git a/pubspec.lock b/pubspec.lock index c8002862..e842bc7c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -576,14 +576,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.2.0" - flutter_staggered_grid_view: - dependency: "direct main" - description: - name: flutter_staggered_grid_view - sha256: "19e7abb550c96fbfeb546b23f3ff356ee7c59a019a651f8f102a4ba9b7349395" - url: "https://pub.dev" - source: hosted - version: "0.7.0" flutter_svg: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 26b2ac6a..f7fcd6a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,7 +60,6 @@ dependencies: flutter_inappwebview: ^5.8.0 flutter_local_notifications: ^16.1.0 flutter_mailer: ^2.0.2 - flutter_staggered_grid_view: ^0.7.0 flutter_svg: ^2.0.1 geolocator: ^10.1.0 h3_flutter: ^0.6.6 From cbeec01ed1be0fef7d49148efd2b90bc98a187c8 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 19:12:57 +0330 Subject: [PATCH 3/6] refactor: DApp card file --- .../{new_dapp_card.dart => dapp_card.dart} | 15 +++++++-------- .../responsive_layout/dapp_card_layout.dart | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) rename lib/features/dapps/presentation/responsive_layout/{new_dapp_card.dart => dapp_card.dart} (96%) diff --git a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card.dart similarity index 96% rename from lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart rename to lib/features/dapps/presentation/responsive_layout/dapp_card.dart index a5028298..52d7d49d 100644 --- a/lib/features/dapps/presentation/responsive_layout/new_dapp_card.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card.dart @@ -40,6 +40,8 @@ class DAppCard extends HookConsumerWidget { void Function()? shatter, bool animated = false, }) { + final isMobile = mainAxisCount == CardMainAxisCount.mobile; + final imageRatioFactor = (isMobile ? 0.2 : 0.1); String? image; if (dapp is Bookmark) { if ((dapp as Bookmark).image != null) { @@ -51,9 +53,7 @@ class DAppCard extends HookConsumerWidget { image = dapp.reviewApi!.icon!; } final name = dapp is Bookmark ? (dapp as Bookmark).title : dapp.app!.name!; - final imageSize = width * - (ratioFactor ?? - (mainAxisCount == CardMainAxisCount.mobile ? 0.2 : 0.1)); + final imageSize = width * (ratioFactor ?? imageRatioFactor); return GestureDetector( onTap: () { if (animated) { @@ -157,9 +157,7 @@ class DAppCard extends HookConsumerWidget { BuildContext context, WidgetRef ref, ) { - final state = ref.watch(appsPagePageContainer.state); final actions = ref.read(appsPagePageContainer.actions); - final dapps = state.orderedDapps; final dappAbout = dapp is Bookmark ? (dapp as Bookmark).title : dapp.app!.description!; final dappUrl = dapp is Bookmark ? (dapp as Bookmark).url : dapp.app!.url!; @@ -252,10 +250,11 @@ class DAppCard extends HookConsumerWidget { child: Text(FlutterI18n.translate(context, 'remove_dapp'), style: FontTheme.of(context).body1Cl())) ]; + final isMobile = mainAxisCount == CardMainAxisCount.mobile; - final size = (mainAxisCount == CardMainAxisCount.mobile ? 0.5 : 0.3); - final sizeLimit = - (mainAxisCount == CardMainAxisCount.mobile ? 0.6000 : 0.6666); + final imageRatioFactor = (isMobile ? 0.2 : 0.1); + final size = (isMobile ? 0.4 : 0.3); + final sizeLimit = imageRatioFactor / size; Widget getCardItem({void Function()? shatter}) { final contextMenuActions = dapp is Bookmark? diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart index 6346cccb..ec6e8e3f 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart @@ -10,7 +10,7 @@ import '../widgets/dapp_indicator.dart'; import 'card_item.dart'; import 'dapp_loading.dart'; import 'dapp_utils.dart'; -import 'new_dapp_card.dart'; +import 'dapp_card.dart'; class DappCardLayout extends HookConsumerWidget { const DappCardLayout({ From 0b4e9d91bc2312bb36b6cd9bbb5c16bd9e27d2e2 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 20:37:48 +0330 Subject: [PATCH 4/6] test: Android testing --- .../splash/create_storage/presentation/create_storage_page.dart | 2 +- lib/features/splash/import_storage/import_storage_page.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/splash/create_storage/presentation/create_storage_page.dart b/lib/features/splash/create_storage/presentation/create_storage_page.dart index 6a910985..d8846ee0 100644 --- a/lib/features/splash/create_storage/presentation/create_storage_page.dart +++ b/lib/features/splash/create_storage/presentation/create_storage_page.dart @@ -85,7 +85,7 @@ class SplashStoragePage extends SplashBasePage { ) : null, ), - isNoneAvailable + !isNoneAvailable ? MxcButton.secondaryWhite( key: const ValueKey('localButton'), icon: Icons.file_download_rounded, diff --git a/lib/features/splash/import_storage/import_storage_page.dart b/lib/features/splash/import_storage/import_storage_page.dart index 6d65b518..06efb43a 100644 --- a/lib/features/splash/import_storage/import_storage_page.dart +++ b/lib/features/splash/import_storage/import_storage_page.dart @@ -62,7 +62,7 @@ class SplashImportStoragePage extends SplashBasePage { ), ), ), - isNoneAvailable + !isNoneAvailable ? MxcButton.secondaryWhite( key: const ValueKey('localButton'), icon: Icons.file_download_rounded, From 0655f6efac21abe1d2ec6068ec5c71188448f9ac Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 20:57:49 +0330 Subject: [PATCH 5/6] fix: other chains dapps & instant loading --- lib/features/dapps/domain/dapp_store_use_case.dart | 9 +++++++-- lib/features/dapps/helpers/reorder_helper.dart | 3 --- lib/features/dapps/presentation/dapps_page.dart | 8 ++++---- lib/features/dapps/presentation/dapps_presenter.dart | 7 +++++-- .../dapps/presentation/responsive_layout/dapp_utils.dart | 8 +++++--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/features/dapps/domain/dapp_store_use_case.dart b/lib/features/dapps/domain/dapp_store_use_case.dart index 2fd26dbd..7e173ad8 100644 --- a/lib/features/dapps/domain/dapp_store_use_case.dart +++ b/lib/features/dapps/domain/dapp_store_use_case.dart @@ -14,12 +14,17 @@ class DappStoreUseCase extends ReactiveUseCase { late final ValueStream> dapps = reactive([]); - loadLocalDApps() async { + Future loadDapps() async { + loadLocalDApps(); + await loadRemoteDApps(); + } + + Future loadLocalDApps() async { final result = await _repository.dappStoreRepository.getAllDappsFromLocal(); update(dapps, result); } - Future getAllDapps() async { + Future loadRemoteDApps() async { final result = await _repository.dappStoreRepository.getAllDapps(); update(dapps, result); diff --git a/lib/features/dapps/helpers/reorder_helper.dart b/lib/features/dapps/helpers/reorder_helper.dart index ee16a837..255c20e5 100644 --- a/lib/features/dapps/helpers/reorder_helper.dart +++ b/lib/features/dapps/helpers/reorder_helper.dart @@ -1,7 +1,4 @@ -import 'dart:async'; - import 'package:datadashwallet/features/dapps/presentation/responsive_layout/dapp_utils.dart'; -import 'package:flutter/material.dart'; import 'package:mxc_logic/mxc_logic.dart'; import '../domain/domain.dart'; diff --git a/lib/features/dapps/presentation/dapps_page.dart b/lib/features/dapps/presentation/dapps_page.dart index 057f1c88..5ad0a388 100644 --- a/lib/features/dapps/presentation/dapps_page.dart +++ b/lib/features/dapps/presentation/dapps_page.dart @@ -1,7 +1,6 @@ import 'package:datadashwallet/common/common.dart'; import 'package:datadashwallet/core/core.dart'; import 'package:datadashwallet/features/common/common.dart'; -import 'package:datadashwallet/features/dapps/dapps.dart'; import 'package:datadashwallet/features/settings/settings.dart'; import 'package:datadashwallet/features/wallet/wallet.dart'; import 'package:flutter/material.dart'; @@ -29,7 +28,8 @@ class DAppsPage extends HookConsumerWidget { return MxcPage( layout: LayoutType.column, useContentPadding: false, - childrenPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), + childrenPadding: const EdgeInsets.symmetric( + horizontal: Sizes.spaceSmall, vertical: Sizes.spaceNormal), backgroundColor: ColorsTheme.of(context).screenBackground, presenter: ref.watch(presenter), appBar: Column( @@ -44,7 +44,7 @@ class DAppsPage extends HookConsumerWidget { leading: IconButton( key: const ValueKey('settingsButton'), icon: const Icon(MxcIcons.settings), - iconSize: 32, + iconSize: Sizes.space2XLarge, onPressed: () { Navigator.of(context).push( route( @@ -57,7 +57,7 @@ class DAppsPage extends HookConsumerWidget { action: IconButton( key: const ValueKey('walletButton'), icon: const Icon(MxcIcons.wallet), - iconSize: 32, + iconSize: Sizes.space2XLarge, onPressed: () => Navigator.of(context).replaceAll( route(const WalletPage()), ), diff --git a/lib/features/dapps/presentation/dapps_presenter.dart b/lib/features/dapps/presentation/dapps_presenter.dart index b76c3b69..f64aa16a 100644 --- a/lib/features/dapps/presentation/dapps_presenter.dart +++ b/lib/features/dapps/presentation/dapps_presenter.dart @@ -96,6 +96,8 @@ class DAppsPagePresenter extends CompletePresenter { listen(_chainConfigurationUseCase.selectedNetwork, (value) { if (value != null) { if (state.network != null && state.network!.chainId != value.chainId) { + DappUtils.loadingOnce = true; + notify(() => state.loading = true); reorderHelper.resetDappsMerge(); } notify(() => state.network = value); @@ -157,7 +159,7 @@ class DAppsPagePresenter extends CompletePresenter { void initializeDapps() async { try { - await _dappStoreUseCase.getAllDapps(); + await _dappStoreUseCase.loadDapps(); } catch (e, s) { addError(e, s); } @@ -171,7 +173,8 @@ class DAppsPagePresenter extends CompletePresenter { void addBookmark() async => bookmarksHelper.addBookmark(); - void updateBookmarkFavIcon(Bookmark item) async => bookmarksHelper.updateBookmarkFavIcon(item); + void updateBookmarkFavIcon(Bookmark item) async => + bookmarksHelper.updateBookmarkFavIcon(item); void onPageChage(int index) => notify(() => state.pageIndex = index); diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_utils.dart b/lib/features/dapps/presentation/responsive_layout/dapp_utils.dart index 56e9b393..7d31cb4c 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_utils.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_utils.dart @@ -25,7 +25,9 @@ class DappUtils { if (e is Bookmark) { return true; } else { - return (e.store!.chainid == chainId) && + return (!MXCChains.isMXCChains(chainId) + ? MXCChains.isMXCMainnet(e.store!.chainid!) + : e.store!.chainid == chainId) && isSupported(e.app!.supportedPlatforms!); } }).toList(); @@ -44,8 +46,8 @@ class DappUtils { // Sort the DApps list based on the order specified in dappsOrder dapps.sort((a, b) { - final aUrl = a is Bookmark ? a.url : a.app!.url!; - final bUrl = b is Bookmark ? b.url : b.app!.url!; + final aUrl = a is Bookmark ? a.url : a.app!.url!; + final bUrl = b is Bookmark ? b.url : b.app!.url!; int indexA = urlIndices[aUrl] ?? dapps.length; int indexB = urlIndices[bUrl] ?? dapps.length; return dappsOrder.indexOf(aUrl) - dappsOrder.indexOf(bUrl); From bae86cdcb541600e3d29c47cf1883a8254eb5dc3 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 23 May 2024 20:58:26 +0330 Subject: [PATCH 6/6] config: Increase version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index f7fcd6a3..a95ef584 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.3.8 +version: 2.3.9 environment: sdk: ">=2.19.0 <3.0.0"