Skip to content

Commit

Permalink
pull to refresh addded
Browse files Browse the repository at this point in the history
  • Loading branch information
n13 committed Jul 28, 2024
1 parent 76d24d2 commit b2e8ea0
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 73 deletions.
35 changes: 20 additions & 15 deletions lib/ui/token/token_settings/components/token_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@ class TokensSettingsView extends StatelessWidget {
final daoTokens = state.tokens.where((t) => t.group == TokenGroup.dao).toList();
final otherTokens = state.tokens.where((t) => t.group == TokenGroup.other).toList();

return ListView(
padding: const EdgeInsets.symmetric(vertical: 26, horizontal: 16),
children: [
if (systemTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'System Tokens'),
...systemTokens.map((token) => _buildTokenItem(context, token)),
],
if (daoTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'DAO Tokens'),
...daoTokens.map((token) => _buildTokenItem(context, token)),
],
if (otherTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'Other Tokens'),
...otherTokens.map((token) => _buildTokenItem(context, token)),
return RefreshIndicator(
onRefresh: () async {
context.read<TokensSettingsBloc>().add(const TokensSettingsEvent.refresh());
},
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 26, horizontal: 16),
children: [
if (systemTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'System Tokens'),
...systemTokens.map((token) => _buildTokenItem(context, token)),
],
if (daoTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'DAO Tokens'),
...daoTokens.map((token) => _buildTokenItem(context, token)),
],
if (otherTokens.isNotEmpty) ...[
_buildGroupHeader(context, 'Other Tokens'),
...otherTokens.map((token) => _buildTokenItem(context, token)),
],
],
],
),
);
},
),
Expand Down
11 changes: 10 additions & 1 deletion lib/ui/token/token_settings/interactor/token_settings_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ class TokensSettingsBloc extends Bloc<TokensSettingsEvent, TokensSettingsState>
this._addTokenToUserUseCase,
) : super(const TokensSettingsState()) {
on<_Initial>(_initial);
on<_Refresh>(_refresh);
on<_AddTokenToUser>(_addTokenToUser);
on<_RemoveTokenToUser>(_removeTokenToUser);
on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null)));
}

Future<void> _initial(_Initial event, Emitter<TokensSettingsState> emit) async {
await _loadTokens(emit);
}

Future<void> _refresh(_Refresh event, Emitter<TokensSettingsState> emit) async {
await _loadTokens(emit);
}

Future<void> _loadTokens(Emitter<TokensSettingsState> emit) async {
emit(state.copyWith(pageState: PageState.loading));

final Stream<List<WalletTokenData>> tokens = await _getAllTokensUseCase.run();
Expand All @@ -45,4 +54,4 @@ class TokensSettingsBloc extends Bloc<TokensSettingsEvent, TokensSettingsState>
FutureOr<void> _removeTokenToUser(_RemoveTokenToUser event, Emitter<TokensSettingsState> emit) async {
await _removeTokenFromUserUseCase.run(event.token.id);
}
}
}
Loading

0 comments on commit b2e8ea0

Please sign in to comment.