From 0cfd7ba2b07807fc5d274f2a154479d72ab9e295 Mon Sep 17 00:00:00 2001 From: guenoel Date: Thu, 17 Nov 2022 15:43:49 +0100 Subject: [PATCH] refacto: headerprofileview --- lib/providers/wallets_profiles.dart | 103 ----------------------- lib/screens/activity.dart | 7 +- lib/screens/wallet_view.dart | 4 +- lib/widgets/header_profile_view.dart | 119 +++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 108 deletions(-) create mode 100644 lib/widgets/header_profile_view.dart diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index 2d3a71c..67af2c8 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -1,20 +1,13 @@ import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/g1_wallets_list.dart'; -import 'package:gecko/models/widgets_keys.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); @@ -129,102 +122,6 @@ class WalletsProfilesProvider with ChangeNotifier { 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); - - return Stack(children: [ - Consumer(builder: (context, sub, _) { - bool isAccountExist = balanceCache[address] != 0; - 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: keyCopyAddress, - 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), - ]); - } - bool isContact(String address) { return contactsBox.containsKey(address); } diff --git a/lib/screens/activity.dart b/lib/screens/activity.dart index 81313dc..a86cdcd 100644 --- a/lib/screens/activity.dart +++ b/lib/screens/activity.dart @@ -8,10 +8,10 @@ import 'package:gecko/models/widgets_keys.dart'; import 'package:gecko/providers/cesium_plus.dart'; import 'package:gecko/providers/duniter_indexer.dart'; import 'package:gecko/providers/substrate_sdk.dart'; -import 'package:gecko/providers/wallets_profiles.dart'; import 'package:flutter/material.dart'; import 'package:gecko/screens/wallet_view.dart'; import 'package:gecko/widgets/bottom_app_bar.dart'; +import 'package:gecko/widgets/header_profile_view.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; @@ -32,8 +32,6 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - WalletsProfilesProvider walletProfile = - Provider.of(context, listen: false); return Scaffold( key: _scaffoldKey, @@ -47,7 +45,8 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { ), bottomNavigationBar: BottomAppBarCustom(context: context), body: Column(children: [ - walletProfile.headerProfileView(context, address, username), + HeaderProfileView( + context: context, address: address, username: username), historyQuery(context), ])); } diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 9171b58..3a36e85 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -19,6 +19,7 @@ import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:gecko/screens/qrcode_fullscreen.dart'; import 'package:gecko/screens/transaction_in_progress.dart'; import 'package:gecko/widgets/bottom_app_bar.dart'; +import 'package:gecko/widgets/header_profile_view.dart'; import 'package:provider/provider.dart'; import 'package:qr_flutter/qr_flutter.dart'; @@ -105,7 +106,8 @@ class WalletViewScreen extends StatelessWidget { bottomNavigationBar: BottomAppBarCustom(context: context), body: SafeArea( child: Column(children: [ - walletProfile.headerProfileView(context, address, username), + HeaderProfileView( + context: context, address: address, username: username), SizedBox(height: isTall ? 10 : 0), Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column(children: [ diff --git a/lib/widgets/header_profile_view.dart b/lib/widgets/header_profile_view.dart new file mode 100644 index 0000000..efc355c --- /dev/null +++ b/lib/widgets/header_profile_view.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/widgets_keys.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/providers/wallets_profiles.dart'; +import 'package:gecko/screens/common_elements.dart'; +import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; + +class HeaderProfileView extends StatelessWidget { + const HeaderProfileView({ + Key? key, + required this.context, + required this.address, + required this.username, + }) : super(key: key); + + final BuildContext context; + final String address; + final String? username; + + @override + Widget build(BuildContext context) { + 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); + + return Stack(children: [ + Consumer(builder: (context, sub, _) { + bool isAccountExist = balanceCache[address] != 0; + 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: keyCopyAddress, + 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), + ]); + } +}