Skip to content

Commit

Permalink
loading indicator and more efficient list view
Browse files Browse the repository at this point in the history
  • Loading branch information
n13 committed Jul 28, 2024
1 parent b2e8ea0 commit c45edf9
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions lib/ui/token/token_settings/components/token_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:hypha_wallet/design/background/hypha_page_background.dart';
import 'package:hypha_wallet/design/hypha_card.dart';
import 'package:hypha_wallet/design/hypha_colors.dart';
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/onboarding/components/onboarding_appbar.dart';
import 'package:hypha_wallet/ui/token/token_settings/interactor/token_settings_bloc.dart';
import 'package:hypha_wallet/ui/wallet/data/wallet_token_data.dart';
Expand All @@ -21,29 +22,29 @@ class TokensSettingsView extends StatelessWidget {
appBar: const OnboardingAppbar(title: 'Available Tokens', subTitle: ''),
body: BlocBuilder<TokensSettingsBloc, TokensSettingsState>(
builder: (context, state) {
final systemTokens = state.tokens.where((t) => t.group == TokenGroup.system).toList();
final daoTokens = state.tokens.where((t) => t.group == TokenGroup.dao).toList();
final otherTokens = state.tokens.where((t) => t.group == TokenGroup.other).toList();
if (state.pageState == PageState.loading) {
return const Center(child: CircularProgressIndicator());
}

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)),
],
child: CustomScrollView(
slivers: [
SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 26, horizontal: 16),
sliver: SliverList(
delegate: SliverChildListDelegate([
_buildTokenGroup(
context, 'System Tokens', state.tokens.where((t) => t.group == TokenGroup.system).toList()),
_buildTokenGroup(
context, 'DAO Tokens', state.tokens.where((t) => t.group == TokenGroup.dao).toList()),
_buildTokenGroup(
context, 'Other Tokens', state.tokens.where((t) => t.group == TokenGroup.other).toList()),
]),
),
),
],
),
);
Expand All @@ -53,6 +54,23 @@ class TokensSettingsView extends StatelessWidget {
);
}

Widget _buildTokenGroup(BuildContext context, String title, List<WalletTokenData> tokens) {
if (tokens.isEmpty) return const SizedBox.shrink();

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildGroupHeader(context, title),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: tokens.length,
itemBuilder: (context, index) => _buildTokenItem(context, tokens[index]),
),
],
);
}

Widget _buildGroupHeader(BuildContext context, String title) {
return Padding(
padding: const EdgeInsets.fromLTRB(10, 16, 10, 8),
Expand Down Expand Up @@ -118,4 +136,4 @@ class TokensSettingsView extends StatelessWidget {
),
);
}
}
}

0 comments on commit c45edf9

Please sign in to comment.