From ce0b8712847a7ee97a5ad106572fc5f5c7401faf Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 3 Jan 2024 08:38:01 -0600 Subject: [PATCH] fix txns v2 not showing up right away on refresh --- .../tx_v2/transaction_v2_list.dart | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_list.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_list.dart index ad2f31024..ed3c3cdd0 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_list.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_list.dart @@ -8,6 +8,8 @@ * */ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:isar/isar.dart'; @@ -40,6 +42,9 @@ class _TransactionsV2ListState extends ConsumerState { bool _hasLoaded = false; List _transactions = []; + late final StreamSubscription> _subscription; + late final QueryBuilder _query; + BorderRadius get _borderRadiusFirst { return BorderRadius.only( topLeft: Radius.circular( @@ -62,19 +67,39 @@ class _TransactionsV2ListState extends ConsumerState { ); } + @override + void initState() { + _query = ref + .read(mainDBProvider) + .isar + .transactionV2s + .where() + .walletIdEqualTo(widget.walletId) + .sortByTimestampDesc(); + + _subscription = _query.watch().listen((event) { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + _transactions = event; + }); + }); + }); + + super.initState(); + } + + @override + void dispose() { + _subscription.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { final coin = ref.watch(pWallets).getWallet(widget.walletId).info.coin; return FutureBuilder( - future: ref - .watch(mainDBProvider) - .isar - .transactionV2s - .where() - .walletIdEqualTo(widget.walletId) - .sortByTimestampDesc() - .findAll(), + future: _query.findAll(), builder: (fbContext, AsyncSnapshot> snapshot) { if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) {