load address ids in futurebuilder

This commit is contained in:
julian-CStack 2023-03-07 07:48:25 -06:00
parent 5f4e8a6e58
commit 8f80b6976f
2 changed files with 16 additions and 10 deletions

View file

@ -21,13 +21,13 @@ import 'package:stackwallet/widgets/rounded_white_container.dart';
class AddressCard extends StatefulWidget { class AddressCard extends StatefulWidget {
const AddressCard({ const AddressCard({
Key? key, Key? key,
required this.address, required this.addressId,
required this.walletId, required this.walletId,
required this.coin, required this.coin,
this.clipboard = const ClipboardWrapper(), this.clipboard = const ClipboardWrapper(),
}) : super(key: key); }) : super(key: key);
final Address address; final int addressId;
final String walletId; final String walletId;
final Coin coin; final Coin coin;
final ClipboardInterface clipboard; final ClipboardInterface clipboard;
@ -38,18 +38,23 @@ class AddressCard extends StatefulWidget {
class _AddressCardState extends State<AddressCard> { class _AddressCardState extends State<AddressCard> {
late Stream<AddressLabel?> stream; late Stream<AddressLabel?> stream;
late final Address address;
AddressLabel? label; AddressLabel? label;
@override @override
void initState() { void initState() {
label = MainDB.instance address = MainDB.instance.isar.addresses
.getAddressLabelSync(widget.walletId, widget.address.value); .where()
.idEqualTo(widget.addressId)
.findFirstSync()!;
label = MainDB.instance.getAddressLabelSync(widget.walletId, address.value);
Id? id = label?.id; Id? id = label?.id;
if (id == null) { if (id == null) {
label = AddressLabel( label = AddressLabel(
walletId: widget.walletId, walletId: widget.walletId,
addressString: widget.address.value, addressString: address.value,
value: "", value: "",
); );
id = MainDB.instance.putAddressLabelSync(label!); id = MainDB.instance.putAddressLabelSync(label!);
@ -97,7 +102,7 @@ class _AddressCardState extends State<AddressCard> {
children: [ children: [
Expanded( Expanded(
child: SelectableText( child: SelectableText(
widget.address.value, address.value,
style: STextStyles.itemSubtitle12(context), style: STextStyles.itemSubtitle12(context),
), ),
) )
@ -119,7 +124,7 @@ class _AddressCardState extends State<AddressCard> {
onPressed: () async { onPressed: () async {
await widget.clipboard.setData( await widget.clipboard.setData(
ClipboardData( ClipboardData(
text: widget.address.value, text: address.value,
), ),
); );
if (mounted) { if (mounted) {
@ -149,7 +154,7 @@ class _AddressCardState extends State<AddressCard> {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (context) => AddressQrPopup( builder: (context) => AddressQrPopup(
addressString: widget.address.value, addressString: address.value,
coin: widget.coin, coin: widget.coin,
clipboard: widget.clipboard, clipboard: widget.clipboard,
), ),

View file

@ -112,8 +112,9 @@ class _WalletAddressesViewState extends ConsumerState<WalletAddressesView> {
.not() .not()
.typeEqualTo(AddressType.nonWallet) .typeEqualTo(AddressType.nonWallet)
.sortByDerivationIndex() .sortByDerivationIndex()
.idProperty()
.findAll(), .findAll(),
builder: (context, AsyncSnapshot<List<Address>> snapshot) { builder: (context, AsyncSnapshot<List<int>> snapshot) {
if (snapshot.connectionState == ConnectionState.done && if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) { snapshot.data != null) {
// listview // listview
@ -124,7 +125,7 @@ class _WalletAddressesViewState extends ConsumerState<WalletAddressesView> {
), ),
itemBuilder: (_, index) => AddressCard( itemBuilder: (_, index) => AddressCard(
walletId: widget.walletId, walletId: widget.walletId,
address: snapshot.data![index], addressId: snapshot.data![index],
coin: coin, coin: coin,
), ),
); );