build method

  1. @override
dynamic build(
  1. dynamic context,
  2. dynamic ref
)

Implementation

@override
Widget build(BuildContext context, WidgetRef ref) {
  final tokensLoader = ref.watch(superInvitesTokensProvider);
  return WithSidebar(
    sidebar: const SettingsPage(),
    child: Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        title: Text(L10n.of(context).superInvites),
        centerTitle: true,
        actions: [
          IconButton(
            icon: const Icon(Atlas.arrows_rotating_right_thin),
            iconSize: 28,
            color: Theme.of(context).colorScheme.surface,
            onPressed: () {
              ref.invalidate(superInvitesTokensProvider);
            },
          ),
          IconButton(
            key: createNewToken,
            icon: const Icon(Atlas.plus_circle_thin),
            iconSize: 28,
            color: Theme.of(context).colorScheme.surface,
            onPressed: () {
              context.pushNamed(Routes.actionCreateSuperInvite.name);
            },
          ),
        ],
      ),
      body: CustomScrollView(
        slivers: [
          const SliverToBoxAdapter(child: RedeemToken()),
          tokensLoader.when(
            data: (tokens) {
              if (tokens.isEmpty) {
                return SliverToBoxAdapter(
                  child: Center(
                    child:
                        Text(L10n.of(context).youHaveNotCreatedInviteCodes),
                  ),
                );
              }
              return SliverList.builder(
                itemBuilder: (context, index) {
                  final token = tokens[index];
                  final acceptedCount =
                      L10n.of(context).usedTimes(token.acceptedCount());
                  final tokenStr = token.token().toString();
                  final firstRoom =
                      token.rooms().map((t) => t.toDartString()).firstOrNull;
                  return Card(
                    key: Key('edit-token-$tokenStr'),
                    margin: const EdgeInsets.all(5),
                    child: Padding(
                      padding: const EdgeInsets.all(5),
                      child: ListTile(
                        title: Text(
                          tokenStr,
                          style: Theme.of(context).textTheme.headlineSmall,
                        ),
                        subtitle: Text(
                          acceptedCount,
                          style: Theme.of(context).textTheme.bodySmall,
                        ),
                        onTap: () {
                          context.pushNamed(
                            Routes.actionCreateSuperInvite.name,
                            extra: token,
                          );
                        },
                        trailing: firstRoom != null
                            ? OutlinedButton(
                                onPressed: () => context.pushNamed(
                                  Routes.shareInviteCode.name,
                                  queryParameters: {
                                    'inviteCode': tokenStr,
                                    'roomId': firstRoom,
                                  },
                                ),
                                child: Text(L10n.of(context).share),
                              )
                            : null,
                      ),
                    ),
                  );
                },
                itemCount: tokens.length,
              );
            },
            error: (e, s) {
              _log.severe('Failed to load the super invite tokens', e, s);
              return SliverToBoxAdapter(
                child: Center(
                  child: Text(L10n.of(context).failedToLoadInviteCodes(e)),
                ),
              );
            },
            loading: () => const Center(
              child: CircularProgressIndicator(),
            ),
          ),
        ],
      ),
    ),
  );
}