From 1a49035cbfb306044c3fc476ed8663729796883b Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 12 Jun 2022 19:43:13 +0200 Subject: [PATCH] fix: bad parent widget in search; improve lost connection info --- lib/screens/home.dart | 14 +- lib/screens/search.dart | 53 +++--- lib/screens/search_result.dart | 312 +++++++++++++++++---------------- 3 files changed, 197 insertions(+), 182 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 8dfc901..fd6fd27 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -121,10 +121,10 @@ class HomeScreen extends StatelessWidget { var connectivityResult = await (Connectivity().checkConnectivity()); + HomeProvider _homeProvider = + Provider.of(ctx, listen: false); if (connectivityResult != ConnectivityResult.mobile && connectivityResult != ConnectivityResult.wifi) { - HomeProvider _homeProvider = - Provider.of(ctx, listen: false); _homeProvider.changeMessage( "Vous n'êtes pas connecté à internet", 0); _sub.nodeConnected = false; @@ -134,7 +134,15 @@ class HomeScreen extends StatelessWidget { .onConnectivityChanged .listen((ConnectivityResult result) async { log.d('Network changed: $result'); - await _sub.connectNode(ctx); + if (result == ConnectivityResult.none) { + _sub.nodeConnected = false; + await _sub.sdk.api.setting.unsubscribeBestNumber(); + _homeProvider.changeMessage( + "Vous n'êtes pas connecté à internet", 0); + _sub.reload(); + } else { + await _sub.connectNode(ctx); + } }); } }); diff --git a/lib/screens/search.dart b/lib/screens/search.dart index 53b77e5..8560503 100644 --- a/lib/screens/search.dart +++ b/lib/screens/search.dart @@ -21,31 +21,31 @@ class SearchScreen extends StatelessWidget { // Provider.of(context, listen: false); return WillPopScope( - onWillPop: () { - _searchProvider.searchController.text = ''; - return Future.value(true); - }, - child: Scaffold( - backgroundColor: backgroundColor, + onWillPop: () { + _searchProvider.searchController.text = ''; + return Future.value(true); + }, + child: Scaffold( + backgroundColor: backgroundColor, - appBar: AppBar( - elevation: 1, - toolbarHeight: 60 * ratio, - title: const SizedBox( - height: 22, - child: Text('Rechercher'), - ), - leading: IconButton( - icon: const Icon(Icons.arrow_back, color: Colors.black), - onPressed: () { - _searchProvider.searchController.text = ''; - Navigator.of(context).pop(); - }), + appBar: AppBar( + elevation: 1, + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Rechercher'), ), - // bottomNavigationBar: _homeProvider.bottomAppBar(context), - body: SafeArea( - child: Column(children: [ - CommonElements().offlineInfo(context), + leading: IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + _searchProvider.searchController.text = ''; + Navigator.of(context).pop(); + }), + ), + // bottomNavigationBar: _homeProvider.bottomAppBar(context), + body: SafeArea( + child: Stack(children: [ + Column(children: [ SizedBox(height: isTall ? 200 : 100), Padding( padding: const EdgeInsets.symmetric(horizontal: 17), @@ -113,7 +113,10 @@ class SearchScreen extends StatelessWidget { ), Spacer(flex: screenHeight <= 800 ? 1 : 2), ]), - ), - )); + CommonElements().offlineInfo(context), + ]), + ), + ), + ); } } diff --git a/lib/screens/search_result.dart b/lib/screens/search_result.dart index 0723b04..a0caab8 100644 --- a/lib/screens/search_result.dart +++ b/lib/screens/search_result.dart @@ -42,163 +42,167 @@ class SearchResultScreen extends StatelessWidget { ), bottomNavigationBar: _homeProvider.bottomAppBar(context), body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CommonElements().offlineInfo(context), - const SizedBox(height: 30), - RichText( - text: TextSpan( - style: TextStyle( - fontSize: 18, - color: Colors.grey[700], + child: Stack(children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 30), + RichText( + text: TextSpan( + style: TextStyle( + fontSize: 18, + color: Colors.grey[700], + ), + children: [ + const TextSpan( + text: "Résultats pour ", + ), + TextSpan( + text: '"${_searchProvider.searchController.text}"', + style: const TextStyle(fontStyle: FontStyle.italic), + ), + ], ), - children: [ - const TextSpan( - text: "Résultats pour ", - ), - TextSpan( - text: '"${_searchProvider.searchController.text}"', - style: const TextStyle(fontStyle: FontStyle.italic), - ), - ], ), - ), - const SizedBox(height: 40), - Text( - 'Dans la blockchain $currencyName', - style: const TextStyle(fontSize: 20), - ), - const SizedBox(height: 20), - FutureBuilder( - future: _searchProvider.searchAddress(), - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - log.d(snapshot.data); - if (snapshot.data?.isEmpty ?? true) { - return const Text('Aucun résultat'); - } else { - return Expanded( - child: ListView(children: [ - for (G1WalletsList g1Wallet in snapshot.data ?? []) - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 5), - child: ListTile( - key: Key('searchResult${keyID++}'), - horizontalTitleGap: 40, - contentPadding: const EdgeInsets.all(5), - leading: - // g1WalletsBox.get(g1Wallet.pubkey) - // ?.avatar != - // null - // ? - _cesiumPlusProvider - .defaultAvatar(_avatarSize), - // : FutureBuilder( - // future: _cesiumPlusProvider.getAvatar( - // g1Wallet.pubkey, _avatarSize), - // builder: (BuildContext context, - // AsyncSnapshot _avatar) { - // if (_avatar.connectionState != - // ConnectionState.done || - // _avatar.hasError) { - // return Stack(children: [ - // _cesiumPlusProvider - // .defaultAvatar(_avatarSize), - // Positioned( - // top: 8, - // right: 0, - // width: 12, - // height: 12, - // child: CircularProgressIndicator( - // strokeWidth: 1, - // color: orangeC, - // ), - // ), - // ]); - // } - // if (_avatar.hasData) { - // final _w = - // g1WalletsBox.get(g1Wallet.pubkey); - // if (_w != null) { - // _w.avatar = _avatar.data; - // } - // return ClipOval(child: _avatar.data); - // } else { - // g1WalletsBox - // .get(g1Wallet.pubkey)! - // .avatar = - // _cesiumPlusProvider - // .defaultAvatar(_avatarSize); - // return _cesiumPlusProvider - // .defaultAvatar(_avatarSize); - // } - // }), - title: Row(children: [ - Text(getShortPubkey(g1Wallet.pubkey!), - style: const TextStyle( - fontSize: 18, - fontFamily: 'Monospace', - fontWeight: FontWeight.w500), - textAlign: TextAlign.center), - ]), - trailing: Column( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - balance(context, g1Wallet.pubkey!, 16) - ]), - subtitle: Row(children: [ - Text(g1Wallet.id?.username ?? '', - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w500), - textAlign: TextAlign.center), - ]), - dense: false, - isThreeLine: false, - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - _walletsProfilesClass.address = - g1Wallet.pubkey; - return WalletViewScreen( - pubkey: g1Wallet.pubkey, - username: g1WalletsBox - .get(g1Wallet.pubkey) - ?.id - ?.username, - avatar: g1WalletsBox - .get(g1Wallet.pubkey) - ?.avatar, - ); - }), - ); - }), - ), - ]), - ); + const SizedBox(height: 40), + Text( + 'Dans la blockchain $currencyName', + style: const TextStyle(fontSize: 20), + ), + const SizedBox(height: 20), + FutureBuilder( + future: _searchProvider.searchAddress(), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + log.d(snapshot.data); + if (snapshot.data?.isEmpty ?? true) { + return const Text('Aucun résultat'); + } else { + return Expanded( + child: ListView(children: [ + for (G1WalletsList g1Wallet + in snapshot.data ?? []) + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 5), + child: ListTile( + key: Key('searchResult${keyID++}'), + horizontalTitleGap: 40, + contentPadding: const EdgeInsets.all(5), + leading: + // g1WalletsBox.get(g1Wallet.pubkey) + // ?.avatar != + // null + // ? + _cesiumPlusProvider + .defaultAvatar(_avatarSize), + // : FutureBuilder( + // future: _cesiumPlusProvider.getAvatar( + // g1Wallet.pubkey, _avatarSize), + // builder: (BuildContext context, + // AsyncSnapshot _avatar) { + // if (_avatar.connectionState != + // ConnectionState.done || + // _avatar.hasError) { + // return Stack(children: [ + // _cesiumPlusProvider + // .defaultAvatar(_avatarSize), + // Positioned( + // top: 8, + // right: 0, + // width: 12, + // height: 12, + // child: CircularProgressIndicator( + // strokeWidth: 1, + // color: orangeC, + // ), + // ), + // ]); + // } + // if (_avatar.hasData) { + // final _w = + // g1WalletsBox.get(g1Wallet.pubkey); + // if (_w != null) { + // _w.avatar = _avatar.data; + // } + // return ClipOval(child: _avatar.data); + // } else { + // g1WalletsBox + // .get(g1Wallet.pubkey)! + // .avatar = + // _cesiumPlusProvider + // .defaultAvatar(_avatarSize); + // return _cesiumPlusProvider + // .defaultAvatar(_avatarSize); + // } + // }), + title: Row(children: [ + Text(getShortPubkey(g1Wallet.pubkey!), + style: const TextStyle( + fontSize: 18, + fontFamily: 'Monospace', + fontWeight: FontWeight.w500), + textAlign: TextAlign.center), + ]), + trailing: Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + balance( + context, g1Wallet.pubkey!, 16) + ]), + subtitle: Row(children: [ + Text(g1Wallet.id?.username ?? '', + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500), + textAlign: TextAlign.center), + ]), + dense: false, + isThreeLine: false, + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + _walletsProfilesClass.address = + g1Wallet.pubkey; + return WalletViewScreen( + pubkey: g1Wallet.pubkey, + username: g1WalletsBox + .get(g1Wallet.pubkey) + ?.id + ?.username, + avatar: g1WalletsBox + .get(g1Wallet.pubkey) + ?.avatar, + ); + }), + ); + }), + ), + ]), + ); + } } - } - return Center( - heightFactor: 5, - child: CircularProgressIndicator( - strokeWidth: 3, - backgroundColor: yellowC, - color: orangeC, - ), - ); - }, - ), - // Text( - // _searchProvider.searchResult.toString(), - // ) - ]), - ), + return Center( + heightFactor: 5, + child: CircularProgressIndicator( + strokeWidth: 3, + backgroundColor: yellowC, + color: orangeC, + ), + ); + }, + ), + // Text( + // _searchProvider.searchResult.toString(), + // ) + ]), + ), + CommonElements().offlineInfo(context), + ]), ), ); }