From c664da1f4ec43082f70692896fe61abc84839db7 Mon Sep 17 00:00:00 2001 From: Marcin <84280969+nemoforte@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:23:26 +0200 Subject: [PATCH] Bugfix: Favourite balance refresh (#12) The purpose of this branch is to fix not refreshing favourite balance right after sending tokens. Additionally, it was noticed that on desktop view, adding balances to favourites is broken if there is one record, because emitting list with changed favourites by InfinityListBloc does not cause SliverInfinityList to reload. So this issue was also examined on this branch. List of changes: - added missing "forceRequestBool" parameter while calling initFavourites() in _mapListReloadEventToState() method in a_list_bloc.dart. It allowed refreshing balances by avoiding getting them from cache. - added emit(ListLoadingState()) in _mapListUpdatedEventToState() method in infinity_list_bloc.dart, to ensure the SliverInfinityList is reloaded with each emit, and the favourites will be updated. However, this is not the optimal solution, it may be necessary to rebuild the lists to manage this issue properly. Details can be found in "unify-list_items" ticket on Trello. --- .../widgets/kira/kira_list/abstract_list/a_list_bloc.dart | 4 ++-- .../kira/kira_list/infinity_list/infinity_list_bloc.dart | 4 ++++ pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/blocs/widgets/kira/kira_list/abstract_list/a_list_bloc.dart b/lib/blocs/widgets/kira/kira_list/abstract_list/a_list_bloc.dart index 6e8ee9d2..0b7860ad 100644 --- a/lib/blocs/widgets/kira/kira_list/abstract_list/a_list_bloc.dart +++ b/lib/blocs/widgets/kira/kira_list/abstract_list/a_list_bloc.dart @@ -1,4 +1,4 @@ -import 'dart:async'; + import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -149,7 +149,7 @@ abstract class AListBloc extends Bloc.initial(); lastPageIndex = 0; - await favouritesBloc?.initFavourites(); + await favouritesBloc?.initFavourites(forceRequestBool: true); bool filtersEnabledBool = filtersBloc?.state is FiltersActiveState; bool sortEnabledBool = sortBloc != null; diff --git a/lib/blocs/widgets/kira/kira_list/infinity_list/infinity_list_bloc.dart b/lib/blocs/widgets/kira/kira_list/infinity_list/infinity_list_bloc.dart index 04887348..0935d084 100644 --- a/lib/blocs/widgets/kira/kira_list/infinity_list/infinity_list_bloc.dart +++ b/lib/blocs/widgets/kira/kira_list/infinity_list/infinity_list_bloc.dart @@ -7,6 +7,7 @@ import 'package:miro/blocs/widgets/kira/kira_list/abstract_list/events/list_upda import 'package:miro/blocs/widgets/kira/kira_list/abstract_list/models/a_list_item.dart'; import 'package:miro/blocs/widgets/kira/kira_list/abstract_list/models/page_data.dart'; import 'package:miro/blocs/widgets/kira/kira_list/abstract_list/states/list_loaded_state.dart'; +import 'package:miro/blocs/widgets/kira/kira_list/abstract_list/states/list_loading_state.dart'; import 'package:miro/blocs/widgets/kira/kira_list/favourites/favourites_bloc.dart'; import 'package:miro/blocs/widgets/kira/kira_list/filters/filters_bloc.dart'; import 'package:miro/blocs/widgets/kira/kira_list/infinity_list/events/infinity_list_reached_bottom_event.dart'; @@ -58,6 +59,9 @@ class InfinityListBloc extends AListBloc { end: (lastPageIndex + 1) * singlePageSize, ); + // Loading state was added only to ensure loading state is always emitted. + // In BLoC, if next state is recognized as the same as previous state, it will not be emitted. + emit(ListLoadingState()); emit(ListLoadedState( listItems: visibleListItems, lastPage: currentPageData.lastPageBool, diff --git a/pubspec.yaml b/pubspec.yaml index f548023f..df8dc652 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.28.0 +version: 1.28.1 environment: sdk: ">=3.1.3"