From b03a28035684596e2d3de64b5033259359eaefc7 Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 16 Jun 2022 20:09:35 +0200 Subject: [PATCH] improve headerProfileView: move to provider --- lib/providers/wallets_profiles.dart | 115 +++++++++++++- lib/screens/activity.dart | 91 +---------- lib/screens/wallet_view.dart | 229 +--------------------------- 3 files changed, 125 insertions(+), 310 deletions(-) diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index 731a9a9..a12817e 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -1,11 +1,17 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; +import 'package:gecko/providers/cesium_plus.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:gecko/providers/wallet_options.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/wallet_view.dart'; import 'package:jdenticon_dart/jdenticon_dart.dart'; import 'package:permission_handler/permission_handler.dart'; // import 'package:qrscan/qrscan.dart' as scanner; import 'package:barcode_scan2/barcode_scan2.dart'; +import 'package:provider/provider.dart'; class WalletsProfilesProvider with ChangeNotifier { WalletsProfilesProvider(this.address); @@ -18,7 +24,7 @@ class WalletsProfilesProvider with ChangeNotifier { String? rawSvg; TextEditingController payAmount = TextEditingController(); TextEditingController payComment = TextEditingController(); - num? balance; + num? _balance; Future scan(context) async { if (Platform.isAndroid || Platform.isIOS) { @@ -113,13 +119,116 @@ class WalletsProfilesProvider with ChangeNotifier { // } Future getBalance(String? _pubkey) async { - while (balance == null) { + while (_balance == null) { await Future.delayed(const Duration(milliseconds: 50)); } - return balance; + return _balance; } + +Widget headerProfileView( + BuildContext context, String _address, String? username) { + const double _avatarSize = 140; + + WalletOptionsProvider _walletOptions = + Provider.of(context, listen: false); + CesiumPlusProvider _cesiumPlusProvider = + Provider.of(context, listen: false); + // SubstrateSdk _sub = Provider.of(context, listen: false); + + bool isAccountExist = balanceCache[_address] != 0; + + return Stack(children: [ + Consumer(builder: (context, _sub, _) { + return Container( + height: 180, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + isAccountExist ? yellowC : Colors.grey[400]!, + isAccountExist ? const Color(0xFFE7811A) : Colors.grey[600]!, + ], + ), + )); + }), + Padding( + padding: const EdgeInsets.only(left: 30, right: 40), + child: Row(children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 10, + color: yellowC, // Colors.grey[400], + ), + Row(children: [ + GestureDetector( + key: const Key('copyPubkey'), + onTap: () { + Clipboard.setData(ClipboardData(text: _address)); + snackCopyKey(context); + }, + child: Text( + getShortPubkey(_address), + style: const TextStyle( + fontSize: 30, + fontWeight: FontWeight.w800, + ), + ), + ), + ]), + const SizedBox(height: 25), + + balance(context, _address, 22), + const SizedBox(height: 10), + _walletOptions.idtyStatus(context, _address, + isOwner: false, color: Colors.black), + getCerts(context, _address, 14), + + if (username == null && + g1WalletsBox.get(_address)?.username != null) + SizedBox( + width: 230, + child: Text( + g1WalletsBox.get(_address)?.username ?? '', + style: const TextStyle( + fontSize: 27, + color: Color(0xff814C00), + ), + ), + ), + if (username != null) + SizedBox( + width: 230, + child: Text( + username, + style: const TextStyle( + fontSize: 27, + color: Color(0xff814C00), + ), + ), + ), + const SizedBox(height: 55), + ]), + const Spacer(), + Column(children: [ + ClipOval( + child: _cesiumPlusProvider.defaultAvatar(_avatarSize), + ), + + const SizedBox(height: 25), + ]), + ]), + ), + CommonElements().offlineInfo(context), + ]); + } + + + void reload() { notifyListeners(); } diff --git a/lib/screens/activity.dart b/lib/screens/activity.dart index 27cb32d..18017cf 100644 --- a/lib/screens/activity.dart +++ b/lib/screens/activity.dart @@ -3,8 +3,8 @@ import 'package:gecko/globals.dart'; import 'package:gecko/models/queries_indexer.dart'; import 'package:gecko/providers/cesium_plus.dart'; import 'package:gecko/providers/duniter_indexer.dart'; +import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/substrate_sdk.dart'; -import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:flutter/material.dart'; import 'package:gecko/screens/wallet_view.dart'; @@ -30,6 +30,10 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + WalletsProfilesProvider _walletProfile = + Provider.of(context, listen: false); + HomeProvider _homeProvider = + Provider.of(context, listen: false); return Scaffold( key: _scaffoldKey, @@ -41,8 +45,9 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { child: Text('Activité du compte'), ), ), + bottomNavigationBar: _homeProvider.bottomAppBar(context), body: Column(children: [ - headerProfileView(context), + _walletProfile.headerProfileView(context, address!, username), historyQuery(context), ])); } @@ -342,86 +347,4 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { ]); }).toList()); } - - Widget headerProfileView(BuildContext context) { - DuniterIndexer _duniterIndexer = - Provider.of(context, listen: false); - - return Column(children: [ - Container( - height: 10, - color: yellowC, - ), - Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - yellowC, - const Color(0xFFE7811A), - ], - )), - child: Padding( - padding: const EdgeInsets.only(left: 30, right: 40), - child: Row(children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row(children: [ - GestureDetector( - key: const Key('copyPubkey'), - onTap: () { - Clipboard.setData(ClipboardData(text: address)); - snackCopyKey(context); - }, - child: Text( - getShortPubkey(address!), - style: const TextStyle( - fontSize: 30, - fontWeight: FontWeight.w800, - ), - ), - ), - ]), - const SizedBox(height: 10), - if (username == null) - _duniterIndexer.getNameByAddress( - context, - address!, - null, - 27, - false, - Colors.black, - FontWeight.w400, - FontStyle.normal), - if (username != null) - SizedBox( - width: 230, - child: Text( - username!, - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - const SizedBox(height: 25), - ]), - balance(context, address!, 21), - const SizedBox(height: 30), - ]), - const Spacer(), - Column(children: [ - Image.asset(('assets/icon_user.png'), height: 50), - const SizedBox(height: 25), - ]), - ]), - ), - ), - ]); - } } diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index e2ac1c4..3c4ea93 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -9,7 +9,6 @@ import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/screens/activity.dart'; -import 'package:gecko/screens/avatar_fullscreen.dart'; import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/myWallets/choose_wallet.dart'; import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; @@ -31,11 +30,11 @@ class WalletViewScreen extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - WalletsProfilesProvider _walletViewProvider = + WalletsProfilesProvider _walletProfile = Provider.of(context, listen: false); CesiumPlusProvider _cesiumPlusProvider = Provider.of(context, listen: false); - _walletViewProvider.address = pubkey!; + _walletProfile.address = pubkey!; SubstrateSdk _sub = Provider.of(context, listen: false); HomeProvider _homeProvider = Provider.of(context, listen: false); @@ -58,13 +57,13 @@ class WalletViewScreen extends StatelessWidget { context, MaterialPageRoute(builder: (context) { return QrCodeFullscreen( - _walletViewProvider.address!, + _walletProfile.address!, ); }), ); }, child: QrImageWidget( - data: _walletViewProvider.address!, + data: _walletProfile.address!, version: QrVersions.auto, size: 80, ), @@ -76,12 +75,9 @@ class WalletViewScreen extends StatelessWidget { ), ), bottomNavigationBar: _homeProvider.bottomAppBar(context), - // floatingActionButton: _homeProvider.floatingAction(context, 1), - // floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, body: SafeArea( child: Column(children: [ - headerProfileView( - context, _walletViewProvider, _cesiumPlusProvider), + _walletProfile.headerProfileView(context, pubkey!, username), SizedBox(height: isTall ? 10 : 0), Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column(children: [ @@ -382,7 +378,7 @@ class WalletViewScreen extends StatelessWidget { )), onTap: _sub.nodeConnected ? () { - paymentPopup(context, _walletViewProvider); + paymentPopup(context, _walletProfile); } : null), ), @@ -695,217 +691,4 @@ class WalletViewScreen extends StatelessWidget { }); }).then((value) => _walletViewProvider.payAmount.text = ''); } - - Widget headerProfileView( - BuildContext context, - WalletsProfilesProvider _historyProvider, - CesiumPlusProvider _cesiumPlusProvider) { - const double _avatarSize = 140; - - WalletOptionsProvider _walletOptions = - Provider.of(context, listen: false); - // SubstrateSdk _sub = Provider.of(context, listen: false); - - bool isAccountExist = balanceCache[pubkey] != 0; - - return Stack(children: [ - Consumer(builder: (context, _sub, _) { - return Container( - height: 180, - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - isAccountExist ? yellowC : Colors.grey[400]!, - isAccountExist ? const Color(0xFFE7811A) : Colors.grey[600]!, - ], - ), - )); - }), - Padding( - padding: const EdgeInsets.only(left: 30, right: 40), - child: Row(children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - height: 10, - color: yellowC, // Colors.grey[400], - ), - Row(children: [ - GestureDetector( - key: const Key('copyPubkey'), - onTap: () { - Clipboard.setData(ClipboardData(text: pubkey)); - snackCopyKey(context); - }, - child: Text( - getShortPubkey(pubkey!), - style: const TextStyle( - fontSize: 30, - fontWeight: FontWeight.w800, - ), - ), - ), - ]), - const SizedBox(height: 25), - - balance(context, pubkey!, 22), - const SizedBox(height: 10), - _walletOptions.idtyStatus(context, pubkey!, - isOwner: false, color: Colors.black), - getCerts(context, pubkey!, 14), - - // if (username == null && - // g1WalletsBox.get(pubkey)?.username == null) - // Query( - // options: QueryOptions( - // document: gql(getId), - // variables: { - // 'pubkey': pubkey, - // }, - // ), - // builder: (QueryResult result, - // {VoidCallback? refetch, FetchMore? fetchMore}) { - // if (result.isLoading || result.hasException) { - // return const Text('...'); - // } else if (result.data!['idty'] == null || - // result.data!['idty']['username'] == null) { - // g1WalletsBox.get(pubkey)?.username = ''; - // return const Text(''); - // } else { - // g1WalletsBox.get(pubkey)?.username = - // result.data!['idty']['username'] ?? ''; - // return SizedBox( - // width: 230, - // child: Text( - // result.data!['idty']['username'] ?? '', - // style: const TextStyle( - // fontSize: 27, - // color: Color(0xff814C00), - // ), - // ), - // ); - // } - // }, - // ), - if (username == null && - g1WalletsBox.get(pubkey)?.username != null) - SizedBox( - width: 230, - child: Text( - g1WalletsBox.get(pubkey)?.username ?? '', - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - if (username != null) - SizedBox( - width: 230, - child: Text( - username!, - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - const SizedBox(height: 25), - //// To get Cs+ name - // FutureBuilder( - // future: _cesiumPlusProvider.getName(pubkey), - // initialData: '...', - // builder: (context, snapshot) { - // return SizedBox( - // width: 230, - // child: Text( - // snapshot.data.toString(), - // style: const TextStyle( - // fontSize: 18, color: Colors.black), - // ), - // ); - // }), - const SizedBox(height: 30), - ]), - const Spacer(), - Column(children: [ - if (avatar == null) - ClipOval( - child: _cesiumPlusProvider.defaultAvatar(_avatarSize), - ), - // FutureBuilder( - // future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize), - // builder: - // (BuildContext context, AsyncSnapshot _avatar) { - // if (_avatar.connectionState != ConnectionState.done) { - // return Stack(children: [ - // ClipOval( - // child: - // _cesiumPlusProvider.defaultAvatar(_avatarSize), - // ), - // Positioned( - // top: 15, - // right: 45, - // width: 51, - // height: 51, - // child: CircularProgressIndicator( - // strokeWidth: 5, - // color: orangeC, - // ), - // ), - // ]); - // } - // if (_avatar.hasData) { - // return GestureDetector( - // key: const Key('openAvatar'), - // onTap: () { - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) { - // return AvatarFullscreen(_avatar.data); - // }), - // ); - // }, - // child: ClipOval( - // child: Image( - // image: _avatar.data!.image, - // height: _avatarSize, - // fit: BoxFit.cover, - // ), - // ), - // ); - // } - // return ClipOval( - // child: _cesiumPlusProvider.defaultAvatar(_avatarSize), - // ); - // }), - if (avatar != null) - GestureDetector( - key: const Key('openAvatar'), - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AvatarFullscreen(avatar); - }), - ); - }, - child: ClipOval( - child: Image( - image: avatar!.image, - height: _avatarSize, - fit: BoxFit.cover, - ), - ), - ), - const SizedBox(height: 25), - ]), - ]), - ), - CommonElements().offlineInfo(context), - ]); - } }