Commit 0ada1635 authored by poka's avatar poka
Browse files

can search username in indexer

parent e90e3063
Pipeline #16105 waiting for manual action with stages
......@@ -7,7 +7,11 @@ import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/queries_indexer.dart';
import 'package:gecko/models/wallet_data.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/wallet_view.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart';
......@@ -106,7 +110,6 @@ class DuniterIndexer with ChangeNotifier {
FontStyle fontStyle = FontStyle.italic]) {
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context, listen: false);
log.d('iiiiiiiiiiiiiiiiiiiiiii $indexerEndpoint');
if (indexerEndpoint == '') {
if (wallet == null) {
return const SizedBox();
......@@ -167,4 +170,91 @@ class DuniterIndexer with ChangeNotifier {
);
});
}
Widget searchIdentity(BuildContext context, String name) {
// WalletOptionsProvider _walletOptions =
// Provider.of<WalletOptionsProvider>(context, listen: false);
CesiumPlusProvider _cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false);
WalletsProfilesProvider _walletsProfiles =
Provider.of<WalletsProfilesProvider>(context, listen: false);
if (indexerEndpoint == '') {
return const Text('Aucun résultat');
}
return Query(
options: QueryOptions(
document: gql(
searchAddressByNameQ), // this is the query string you just created
variables: {
'name': name,
},
// pollInterval: const Duration(seconds: 10),
),
builder: (QueryResult result,
{VoidCallback? refetch, FetchMore? fetchMore}) {
if (result.hasException) {
return Text(result.exception.toString());
}
if (result.isLoading) {
return const Text('Loading');
}
final List identities = result.data?['search_identity'] ?? [];
if (identities.isEmpty) {
return const Text('Aucun résultat');
}
int keyID = 0;
double _avatarSize = 55;
return Expanded(
child: ListView(children: <Widget>[
for (Map profile in identities)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: Key('searchResult${keyID++}'),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: _cesiumPlusProvider.defaultAvatar(_avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(profile['id']),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [balance(context, profile['id'], 16)]),
subtitle: Row(children: <Widget>[
Text(profile['name'] ?? '',
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
_walletsProfiles.address = profile['id'];
return WalletViewScreen(
pubkey: profile['id'],
username:
g1WalletsBox.get(profile['id'])?.id?.username,
avatar: g1WalletsBox.get(profile['id'])?.avatar,
);
}),
);
}),
),
]),
);
});
}
}
......@@ -3,6 +3,7 @@ import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/models/g1_wallets_list.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';
......@@ -26,6 +27,8 @@ class SearchResultScreen extends StatelessWidget {
Provider.of<WalletsProfilesProvider>(context, listen: false);
HomeProvider _homeProvider =
Provider.of<HomeProvider>(context, listen: false);
DuniterIndexer _duniterIndexer =
Provider.of<DuniterIndexer>(context, listen: false);
int keyID = 0;
double _avatarSize = 55;
......@@ -78,7 +81,10 @@ class SearchResultScreen extends StatelessWidget {
if (snapshot.connectionState == ConnectionState.done) {
log.d(snapshot.data);
if (snapshot.data?.isEmpty ?? true) {
return const Text('Aucun résultat');
return _duniterIndexer.searchIdentity(
context, _searchProvider.searchController.text);
// const Text('Aucun résultat');
} else {
return Expanded(
child: ListView(children: <Widget>[
......@@ -91,53 +97,8 @@ class SearchResultScreen extends StatelessWidget {
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<Image?> _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);
// }
// }),
leading: _cesiumPlusProvider
.defaultAvatar(_avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.pubkey!),
style: const TextStyle(
......@@ -154,11 +115,8 @@ class SearchResultScreen extends StatelessWidget {
context, g1Wallet.pubkey!, 16)
]),
subtitle: Row(children: <Widget>[
Text(g1Wallet.id?.username ?? '',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
_duniterIndexer.getNameByAddress(
context, g1Wallet.pubkey!)
]),
dense: false,
isThreeLine: false,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment