order contacts by usernames

This commit is contained in:
poka 2022-08-14 22:16:46 +02:00
parent c6d5b30090
commit d9aa66e1ec
4 changed files with 53 additions and 37 deletions

View File

@ -5,6 +5,7 @@ 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/queries_indexer.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/cesium_plus.dart';
@ -207,6 +208,13 @@ class DuniterIndexer with ChangeNotifier {
walletNameIndexer[address] =
result.data?['account_by_pk']?['identity']?['name'];
g1WalletsBox.put(
address,
G1WalletsList(
pubkey: address, username: walletNameIndexer[address]));
// log.d(g1WalletsBox.toMap().values.first.username);
if (walletNameIndexer[address] == null) {
if (wallet == null) {
return const SizedBox();

View File

@ -187,29 +187,29 @@ class WalletsProfilesProvider with ChangeNotifier {
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),
),
),
),
// 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(),
@ -229,12 +229,12 @@ class WalletsProfilesProvider with ChangeNotifier {
return contactsBox.containsKey(address);
}
void addContact(G1WalletsList profile) {
log.d(profile.username);
Future addContact(G1WalletsList profile) async {
// log.d(profile.username);
if (isContact(profile.pubkey!)) {
contactsBox.delete(profile.pubkey);
await contactsBox.delete(profile.pubkey);
} else {
contactsBox.put(profile.pubkey, profile);
await contactsBox.put(profile.pubkey, profile);
}
notifyListeners();
}

View File

@ -22,7 +22,7 @@ class ContactsScreen extends StatelessWidget {
CesiumPlusProvider cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false);
WalletsProfilesProvider walletsProfilesClass =
Provider.of<WalletsProfilesProvider>(context, listen: false);
Provider.of<WalletsProfilesProvider>(context, listen: true);
HomeProvider homeProvider =
Provider.of<HomeProvider>(context, listen: false);
DuniterIndexer duniterIndexer =
@ -32,11 +32,15 @@ class ContactsScreen extends StatelessWidget {
double avatarSize = 55;
final myContacts = contactsBox.toMap().values.toList();
// myContacts.sort((a, b) {
// final aa = a.username?.toLowerCase() ?? '';
// final bb = b.username?.toLowerCase() ?? '';
// return aa.compareTo(bb);
// });
// 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');
});
return Scaffold(
backgroundColor: backgroundColor,

View File

@ -60,10 +60,14 @@ class WalletViewScreen extends StatelessWidget {
Consumer<WalletsProfilesProvider>(
builder: (context, walletProfile, _) {
return IconButton(
onPressed: () {
final newContact =
G1WalletsList(pubkey: pubkey!, username: username);
walletProfile.addContact(newContact);
onPressed: () async {
G1WalletsList? newContact;
g1WalletsBox.toMap().forEach((key, value) {
if (key == pubkey) newContact = value;
});
// G1WalletsList(pubkey: pubkey!, username: username);
await walletProfile.addContact(
newContact ?? G1WalletsList(pubkey: pubkey!));
},
icon: Icon(
walletProfile.isContact(pubkey!)