From d76ad9b7e373d3db5607fe9b10568100aeac68e7 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 12 Sep 2022 07:26:13 +0200 Subject: [PATCH] improve dargndrop UX --- assets/translations/en.json | 4 +- assets/translations/es.json | 4 +- assets/translations/fr.json | 4 +- lib/providers/my_wallets.dart | 2 + lib/screens/myWallets/wallets_home.dart | 231 +++++++++++++++--------- pubspec.yaml | 2 +- 6 files changed, 157 insertions(+), 90 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 84e6836..6b60dcd 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -158,6 +158,7 @@ "months": "{} months", "certify": "Certify", "from": "From:", + "to": "To:", "amount": "Amount:", "choiceOfSourceWallet": "Choose a source wallet", "extrinsicInProgress": "{} in progress", @@ -193,5 +194,6 @@ "revokeMyIdentity": "Revoke my identity", "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", "showUdAmounts": "Show amounts in UD", - "ud": "{}UD" + "ud": "{}UD", + "chooseATargetWallet": "Choose a target wallet" } \ No newline at end of file diff --git a/assets/translations/es.json b/assets/translations/es.json index 16e8025..81688ce 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -158,6 +158,7 @@ "months": "{} months", "certify": "Certify", "from": "From:", + "to": "To:", "amount": "Amount:", "choiceOfSourceWallet": "Choose a source wallet", "extrinsicInProgress": "{} in progress", @@ -193,5 +194,6 @@ "revokeMyIdentity": "Revoke my identity", "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", "showUdAmounts": "Show amounts in UD", - "ud": "{}UD" + "ud": "{}UD", + "chooseATargetWallet": "Choose a target wallet" } \ No newline at end of file diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 99164e8..9e3021b 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -159,6 +159,7 @@ "months": "{} mois", "certify": "Certifier", "from": "Depuis:", + "to": "Vers:", "amount": "Montant:", "choiceOfSourceWallet": "Choix du portefeuille source", "extrinsicInProgress": "{} en cours", @@ -194,5 +195,6 @@ "revokeMyIdentity": "Révoquer mon identité", "youCannotRevokeThisIdentity": "Vous ne pouvez pas révoquer cette identité tant\nqu'elle fait partie de la toile forgerons", "showUdAmounts": "Afficher les montants en DU", - "ud": "{}DU" + "ud": "{}DU", + "chooseATargetWallet": "Choisissez un portefeuille cible" } \ No newline at end of file diff --git a/lib/providers/my_wallets.dart b/lib/providers/my_wallets.dart index b38c122..dc41080 100644 --- a/lib/providers/my_wallets.dart +++ b/lib/providers/my_wallets.dart @@ -13,6 +13,8 @@ class MyWalletsProvider with ChangeNotifier { late String mnemonic; int? pinLenght; bool isNewDerivationLoading = false; + String lastFlyBy = ''; + String dragAddress = ''; int getCurrentChest() { if (configBox.get('currentChest') == null) { diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index b314d5b..ed73fb4 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -1,7 +1,10 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/widgets_keys.dart'; @@ -64,7 +67,9 @@ class WalletsHome extends StatelessWidget { style: TextStyle(color: Colors.grey[850])), backgroundColor: const Color(0xffFFD58D), ), - bottomNavigationBar: homeProvider.bottomAppBar(context), + bottomNavigationBar: myWalletProvider.lastFlyBy == '' + ? homeProvider.bottomAppBar(context) + : dragInfo(context), body: SafeArea( child: Stack(children: [ myWalletsTiles(context, currentChestNumber), @@ -75,6 +80,37 @@ class WalletsHome extends StatelessWidget { ); } + Widget dragInfo(BuildContext context) { + final myWalletProvider = + Provider.of(context, listen: false); + + final walletDataFrom = + myWalletProvider.getWalletDataByAddress(myWalletProvider.dragAddress); + final walletDataTo = + myWalletProvider.getWalletDataByAddress(myWalletProvider.lastFlyBy); + + final bool isSameAddress = + myWalletProvider.dragAddress == myWalletProvider.lastFlyBy; + + final double screenWidth = MediaQuery.of(homeContext).size.width; + return Container( + color: yellowC, + width: screenWidth, + height: 80, + child: Center( + child: Column( + children: [ + const SizedBox(height: 5), + Text('${'executeATransfer'.tr()}:'), + MarkdownBody(data: '${'from'.tr()} **${walletDataFrom!.name}**'), + if (isSameAddress) Text('chooseATargetWallet'.tr()), + if (!isSameAddress) + MarkdownBody(data: 'Vers: **${walletDataTo!.name}**'), + ], + )), + ); + } + Widget chestOptions( BuildContext context, MyWalletsProvider myWalletProvider) { return Column(children: [ @@ -187,6 +223,7 @@ class WalletsHome extends StatelessWidget { } else if (screenWidth >= 650) { nTule = 3; } + // final dragAnchorStrategy = pointerDragAnchorStrategy; return CustomScrollView(slivers: [ const SliverToBoxAdapter(child: SizedBox(height: 20)), @@ -199,10 +236,19 @@ class WalletsHome extends StatelessWidget { children: [ for (WalletData repository in listWallets as Iterable) LongPressDraggable( + delay: const Duration(milliseconds: 200), data: repository.address!, - dragAnchorStrategy: - (Draggable _, BuildContext __, Offset ___) => - const Offset(0, 0), + // dragAnchorStrategy: + // (Draggable _, BuildContext __, Offset ___) => + // const Offset(40, 40), + dragAnchorStrategy: pointerDragAnchorStrategy, + onDragStarted: () => + myWalletProvider.dragAddress = repository.address!, + onDragEnd: (_) { + myWalletProvider.lastFlyBy = ''; + myWalletProvider.dragAddress = ''; + myWalletProvider.reload(); + }, feedback: ElevatedButton( onPressed: () {}, style: ElevatedButton.styleFrom( @@ -215,96 +261,109 @@ class WalletsHome extends StatelessWidget { child: Image(image: AssetImage('assets/vector_white.png')), ), ), - child: DragTarget(onAccept: (senderAddress) async { - log.d( - 'INTERPAY: sender: $senderAddress --- receiver: ${repository.address!}'); - final walletData = - myWalletProvider.getWalletDataByAddress(senderAddress); - await sub.setCurrentWallet(walletData!); - sub.reload(); - paymentPopup(context, repository.address!); - }, builder: ( - BuildContext context, - List accepted, - List rejected, - ) { - return Padding( - padding: const EdgeInsets.all(16), - child: GestureDetector( - key: keyOpenWallet(repository.address!), - onTap: () { - walletOptions.getAddress( - currentChestNumber, repository.derivation!); - Navigator.push( - context, - SmoothTransition( - page: WalletOptions( - wallet: repository, + child: DragTarget( + onAccept: (senderAddress) async { + log.d( + 'INTERPAY: sender: $senderAddress --- receiver: ${repository.address!}'); + final walletData = myWalletProvider + .getWalletDataByAddress(senderAddress); + await sub.setCurrentWallet(walletData!); + sub.reload(); + paymentPopup(context, repository.address!); + }, + // onMove: ((details) => log.d('oooookkkkkkkk')), + onMove: (details) { + if (repository.address! != myWalletProvider.lastFlyBy) { + log.d('oooookkkkkkkk: ${repository.address!}'); + myWalletProvider.lastFlyBy = repository.address!; + myWalletProvider.reload(); + } + }, + onWillAccept: (senderAddress) => + senderAddress != repository.address!, + builder: ( + BuildContext context, + List accepted, + List rejected, + ) { + return Padding( + padding: const EdgeInsets.all(16), + child: GestureDetector( + key: keyOpenWallet(repository.address!), + onTap: () { + walletOptions.getAddress( + currentChestNumber, repository.derivation!); + Navigator.push( + context, + SmoothTransition( + page: WalletOptions( + wallet: repository, + ), ), + ); + }, + child: ClipOvalShadow( + shadow: const Shadow( + color: Colors.transparent, + offset: Offset(0, 0), + blurRadius: 5, ), - ); - }, - child: ClipOvalShadow( - shadow: const Shadow( - color: Colors.transparent, - offset: Offset(0, 0), - blurRadius: 5, - ), - clipper: CustomClipperOval(), - child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(12)), - child: Column(children: [ - Expanded( - child: Container( - width: double.infinity, - height: double.infinity, - decoration: BoxDecoration( - gradient: RadialGradient( - radius: 0.6, - colors: [ - Colors.green[400]!, - const Color(0xFFE7E7A6), - ], - )), - child: - // SvgPicture.asset('assets/chopp-gecko2.png', - // semanticsLabel: 'Gecko', height: 48), - repository.imageCustomPath == null || - repository.imageCustomPath == '' - ? Image.asset( - 'assets/avatars/${repository.imageDefaultPath}', - alignment: Alignment.bottomCenter, - scale: 0.5, - ) - : Container( - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.transparent, - image: DecorationImage( - fit: BoxFit.fitHeight, - image: FileImage( - File(repository - .imageCustomPath!), + clipper: CustomClipperOval(), + child: ClipRRect( + borderRadius: + const BorderRadius.all(Radius.circular(12)), + child: Column(children: [ + Expanded( + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + gradient: RadialGradient( + radius: 0.6, + colors: [ + Colors.green[400]!, + const Color(0xFFE7E7A6), + ], + )), + child: + // SvgPicture.asset('assets/chopp-gecko2.png', + // semanticsLabel: 'Gecko', height: 48), + repository.imageCustomPath == null || + repository.imageCustomPath == '' + ? Image.asset( + 'assets/avatars/${repository.imageDefaultPath}', + alignment: Alignment.bottomCenter, + scale: 0.5, + ) + : Container( + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.transparent, + image: DecorationImage( + fit: BoxFit.fitHeight, + image: FileImage( + File(repository + .imageCustomPath!), + ), ), ), ), - ), - )), - Stack(children: [ - balanceBuilder( - context, - repository.address!, - repository.address == - defaultWallet.address), - nameBuilder(context, repository, defaultWallet, - currentChestNumber), + )), + Stack(children: [ + balanceBuilder( + context, + repository.address!, + repository.address == + defaultWallet.address), + nameBuilder(context, repository, + defaultWallet, currentChestNumber), + ]), ]), - ]), + ), ), ), - )); - }), + ); + }), ), Consumer(builder: (context, sub, _) { return sub.nodeConnected diff --git a/pubspec.yaml b/pubspec.yaml index 3e57510..e64697b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: Pay with G1. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.11+28 +version: 0.0.11+29 environment: sdk: '>=2.12.0 <3.0.0'