refacto: ContactsList and SearchResult Widget

This commit is contained in:
poka 2022-12-09 03:36:46 +01:00
parent 875341a804
commit c6cfb4e548
9 changed files with 281 additions and 214 deletions

View File

@ -8,6 +8,7 @@ import 'package:gecko/globals.dart';
import 'package:gecko/models/queries_indexer.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/providers/search.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/wallet_view.dart';
@ -159,6 +160,7 @@ class DuniterIndexer with ChangeNotifier {
WalletsProfilesProvider walletsProfiles =
Provider.of<WalletsProfilesProvider>(context, listen: false);
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
final searchProvider = Provider.of<SearchProvider>(context, listen: false);
if (indexerEndpoint == '') {
return const Text('Aucun résultat');
}
@ -207,6 +209,9 @@ class DuniterIndexer with ChangeNotifier {
.putIfAbsent(profile['pubkey'], () => profile['name']);
}
searchProvider.resultLenght = identities.length;
// TODO: Find a way to reload a provider here, in Widget build...
double avatarSize = 55;
return Expanded(
child: ListView(children: <Widget>[

View File

@ -7,6 +7,7 @@ class SearchProvider with ChangeNotifier {
List searchResult = [];
final cacheDuring = 20 * 60 * 1000; //First number is minutes
int cacheTime = 0;
int resultLenght = 0;
void reload() {
notifyListeners();

View File

@ -92,7 +92,6 @@ class _HomeScreenState extends State<HomeScreen> {
// sub.nodeConnected = false;
// }
// TODO: fix random bad network status on startup
HomeProvider homeProvider =
Provider.of<HomeProvider>(context, listen: false);
Connectivity()

View File

@ -62,7 +62,7 @@ class WalletsHome extends StatelessWidget {
children: [
Image.asset(
'assets/chests/${currentChest.imageName}',
height: 40,
height: 32,
),
const SizedBox(width: 17),
Text(currentChest.name!,

View File

@ -2,18 +2,11 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/widgets_keys.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/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:gecko/widgets/balance.dart';
import 'package:gecko/widgets/bottom_app_bar.dart';
import 'package:gecko/widgets/name_by_address.dart';
import 'package:gecko/widgets/contacts_list.dart';
import 'package:provider/provider.dart';
class ContactsScreen extends StatelessWidget {
@ -24,15 +17,9 @@ class ContactsScreen extends StatelessWidget {
WalletsProfilesProvider walletsProfilesClass =
Provider.of<WalletsProfilesProvider>(context, listen: true);
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
double avatarSize = 55;
final myContacts = contactsBox.toMap().values.toList();
// for (var element in myContacts) {
// log.d('yooo: ${element.pubkey} ${element.username}');
// }
myContacts.sort((p1, p2) {
return Comparable.compare(p1.username?.toLowerCase() ?? 'zz',
p2.username?.toLowerCase() ?? 'zz');
@ -52,85 +39,11 @@ class ContactsScreen extends StatelessWidget {
bottomNavigationBar: const GeckoBottomAppBar(),
body: SafeArea(
child: Stack(children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 20),
if (myContacts.isEmpty)
Text('noContacts'.tr())
else
Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in myContacts)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: keySearchResult('keyID++'),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: defaultAvatar(avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.address),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 110,
child: Row(
mainAxisAlignment:
MainAxisAlignment.end,
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Balance(
address:
g1Wallet.address,
size: 16),
]),
]),
),
]),
subtitle: Row(children: <Widget>[
NameByAddress(
wallet:
WalletData(address: g1Wallet.address))
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
walletsProfilesClass.address =
g1Wallet.address;
return WalletViewScreen(
address: g1Wallet.address,
username:
duniterIndexer.walletNameIndexer[
g1Wallet.address] ??
'',
avatar: g1WalletsBox
.get(g1Wallet.address)
?.avatar,
);
}),
);
}),
),
]),
)
]),
),
ContactsList(
myContacts: myContacts,
avatarSize: avatarSize,
walletsProfilesClass: walletsProfilesClass,
duniterIndexer: duniterIndexer),
CommonElements().offlineInfo(context),
]),
),

View File

@ -90,7 +90,7 @@ class _SearchScreenState extends State<SearchScreen> {
textAlign: TextAlign.left,
onChanged: (v) async => {
await getClipBoard(),
setState(() {}),
// setState(() {}),
searchProvider.reload()
},
decoration: InputDecoration(
@ -99,6 +99,23 @@ class _SearchScreenState extends State<SearchScreen> {
prefixIconConstraints: const BoxConstraints(
minHeight: 32,
),
suffixIcon: searchProvider.searchController.text == ''
? null
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 17),
child: IconButton(
onPressed: (() async => {
searchProvider.searchController.text = '',
await getClipBoard(),
searchProvider.reload(),
}),
icon: Icon(
Icons.close,
color: Colors.grey[600],
size: 30,
),
),
),
prefixIcon: const Padding(
padding: EdgeInsets.symmetric(horizontal: 17),
child: Image(

View File

@ -2,19 +2,12 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/widgets_keys.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/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/providers/search.dart';
import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:gecko/widgets/balance.dart';
import 'package:gecko/widgets/bottom_app_bar.dart';
import 'package:gecko/widgets/name_by_address.dart';
import 'package:gecko/widgets/search_result_list.dart';
import 'package:provider/provider.dart';
class SearchResultScreen extends StatelessWidget {
@ -28,6 +21,13 @@ class SearchResultScreen extends StatelessWidget {
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
double avatarSize = 55;
// List<G1WalletsList> myContacts = contactsBox.toMap().values.toList();
// myContacts = myContacts
// .where((map) =>
// (map.username ?? '').contains(searchProvider.searchController.text))
// .toList();
// final searchProvider.resultLenght.toString();
return Scaffold(
backgroundColor: backgroundColor,
@ -48,126 +48,42 @@ class SearchResultScreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 30),
RichText(
text: TextSpan(
style: TextStyle(
fontSize: 18,
color: Colors.grey[700],
),
children: <TextSpan>[
TextSpan(
text: "resultsFor".tr(),
),
TextSpan(
text: '"${searchProvider.searchController.text}"',
style: const TextStyle(fontStyle: FontStyle.italic),
Center(
child: Column(
children: <Widget>[
Text(
"resultsFor".tr(),
style: TextStyle(color: Colors.grey[600]),
),
Text(
'"${searchProvider.searchController.text}"',
style: const TextStyle(
fontStyle: FontStyle.italic, fontSize: 21),
)
],
),
),
// const SizedBox(height: 40),
// Text(
// 'Dans mes contacts'.tr(args: [currencyName]),
// style: const TextStyle(fontSize: 20),
// ),
// ContactsList(
// myContacts: myContacts,
// avatarSize: avatarSize,
// walletsProfilesClass: walletsProfilesClass,
// duniterIndexer: duniterIndexer),
const SizedBox(height: 40),
Text(
'inBlockchainResult'.tr(args: [currencyName]),
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 20),
FutureBuilder(
future: searchProvider.searchAddress(),
builder: (context, AsyncSnapshot<List?> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data?.isEmpty ?? true) {
return duniterIndexer.searchIdentity(
context, searchProvider.searchController.text);
// const Text('Aucun résultat');
} else {
return Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet
in snapshot.data ?? [])
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: keySearchResult(g1Wallet.address),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: defaultAvatar(avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.address),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
SizedBox(
width: 110,
child: Row(
mainAxisAlignment:
MainAxisAlignment.end,
children: [
Column(
mainAxisAlignment:
MainAxisAlignment
.center,
children: [
Balance(
address: g1Wallet
.address,
size: 16),
]),
]),
),
]),
subtitle: Row(children: <Widget>[
NameByAddress(
wallet: WalletData(
address: g1Wallet.address),
),
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
walletsProfilesClass.address =
g1Wallet.address;
return WalletViewScreen(
address: g1Wallet.address,
username: duniterIndexer
.walletNameIndexer[
g1Wallet.address] ??
'',
avatar: g1WalletsBox
.get(g1Wallet.address)
?.avatar,
);
}),
);
}),
),
]),
);
}
}
return const Center(
heightFactor: 5,
child: CircularProgressIndicator(
strokeWidth: 3,
backgroundColor: yellowC,
color: orangeC,
),
);
},
),
// Text(
// _searchProvider.searchResult.toString(),
// )
SearchResult(
searchProvider: searchProvider,
duniterIndexer: duniterIndexer,
avatarSize: avatarSize,
walletsProfilesClass: walletsProfilesClass),
]),
),
CommonElements().offlineInfo(context),

View File

@ -0,0 +1,106 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/wallet_data.dart';
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:gecko/screens/wallet_view.dart';
import 'package:gecko/widgets/balance.dart';
import 'package:gecko/widgets/name_by_address.dart';
class ContactsList extends StatelessWidget {
const ContactsList({
Key? key,
required this.myContacts,
required this.avatarSize,
required this.walletsProfilesClass,
required this.duniterIndexer,
}) : super(key: key);
final List<G1WalletsList> myContacts;
final double avatarSize;
final WalletsProfilesProvider walletsProfilesClass;
final DuniterIndexer duniterIndexer;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 20),
if (myContacts.isEmpty)
Text('noContacts'.tr())
else
Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in myContacts)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: keySearchResult('keyID++'),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: defaultAvatar(avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.address),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 110,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Balance(
address: g1Wallet.address,
size: 16),
]),
]),
),
]),
subtitle: Row(children: <Widget>[
NameByAddress(
wallet: WalletData(address: g1Wallet.address))
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
walletsProfilesClass.address = g1Wallet.address;
return WalletViewScreen(
address: g1Wallet.address,
username: duniterIndexer.walletNameIndexer[
g1Wallet.address] ??
'',
avatar: g1WalletsBox
.get(g1Wallet.address)
?.avatar,
);
}),
);
}),
),
]),
)
]),
);
}
}

View File

@ -0,0 +1,110 @@
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/wallet_data.dart';
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/search.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:gecko/widgets/balance.dart';
import 'package:gecko/widgets/name_by_address.dart';
class SearchResult extends StatelessWidget {
const SearchResult({
Key? key,
required this.searchProvider,
required this.duniterIndexer,
required this.avatarSize,
required this.walletsProfilesClass,
}) : super(key: key);
final SearchProvider searchProvider;
final DuniterIndexer duniterIndexer;
final double avatarSize;
final WalletsProfilesProvider walletsProfilesClass;
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: searchProvider.searchAddress(),
builder: (context, AsyncSnapshot<List?> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data?.isEmpty ?? true) {
return duniterIndexer.searchIdentity(
context, searchProvider.searchController.text);
// const Text('Aucun résultat');
} else {
return Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in snapshot.data ?? [])
resultTile(g1Wallet, context),
]),
);
}
}
return const Center(
heightFactor: 5,
child: CircularProgressIndicator(
strokeWidth: 3,
backgroundColor: yellowC,
color: orangeC,
),
);
},
);
}
Padding resultTile(G1WalletsList g1Wallet, BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: keySearchResult(g1Wallet.address),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: defaultAvatar(avatarSize),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.address),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing:
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
SizedBox(
width: 110,
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Balance(address: g1Wallet.address, size: 16),
]),
]),
),
]),
subtitle: Row(children: <Widget>[
NameByAddress(
wallet: WalletData(address: g1Wallet.address),
),
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
walletsProfilesClass.address = g1Wallet.address;
return WalletViewScreen(
address: g1Wallet.address,
username:
duniterIndexer.walletNameIndexer[g1Wallet.address] ?? '',
avatar: g1WalletsBox.get(g1Wallet.address)?.avatar,
);
}),
);
}),
);
}
}