build method

  1. @override
Widget build(
  1. BuildContext context,
  2. WidgetRef ref
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context, WidgetRef ref) {
  final theme = Theme.of(context);
  final l10n = AppLocalizations.of(context);
  final isPlatformAdmin = ref.watch(isPlatformAdminProvider).value == true;
  final hasOrgs =
      ref.watch(myOrganizationsProvider).value?.isNotEmpty == true;

  // On mobile the parent shell's `_MobileTopBar` already renders the
  // hamburger + "Settings" title, so the inner AppBar would stack as
  // duplicate chrome. Render it only on desktop (no topbar there) where
  // it serves as the title + back affordance.
  final isWide = MediaQuery.sizeOf(context).width >= desktopBreakpoint;
  return Scaffold(
    appBar: isWide
        ? AppBar(
            leading: IconButton(
              icon: const Icon(Icons.arrow_back_rounded),
              tooltip: l10n.settingsBack,
              onPressed: () {
                if (Navigator.of(context).canPop()) {
                  Navigator.of(context).pop();
                } else {
                  GoRouter.of(context).go('/');
                }
              },
            ),
            title: Text(l10n.settingsTitle),
          )
        : null,
    body: WebContentFrame(
      variant: WebLayoutVariant.form,
      child: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          const _FunctionUpdatesBanner(),

          SettingsSectionHeader(title: l10n.settingsAppearance),
          const SizedBox(height: 12),
          const _ThemeModeTile(),
          const SizedBox(height: 12),
          const _LanguageTile(),
          const SizedBox(height: 24),

          SettingsSectionHeader(title: l10n.settingsPreferences),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.person_rounded,
            title: l10n.acctTitle,
            subtitle: l10n.settingsAccountSub,
            onTap: () => context.go('/settings/account'),
          ),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.card_membership_rounded,
            title: l10n.settingsBilling,
            subtitle: l10n.settingsBillingSub,
            onTap: () => context.go('/settings/subscription'),
          ),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.menu_book_rounded,
            title: l10n.settingsLearning,
            subtitle: l10n.settingsLearningSub,
            onTap: () => context.go('/settings/learning'),
          ),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.notifications_rounded,
            title: l10n.settingsNotifications,
            subtitle: l10n.settingsNotificationsSub,
            onTap: () => context.go('/settings/notifications'),
          ),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.lock_rounded,
            title: l10n.settingsPrivacy,
            subtitle: l10n.settingsPrivacySub,
            onTap: () => context.go('/settings/privacy'),
          ),
          const SizedBox(height: 12),
          _indexTile(
            icon: Icons.auto_awesome_rounded,
            title: l10n.aiTitle,
            subtitle: kIsWeb ? l10n.settingsAiSubWeb : l10n.settingsAiSub,
            onTap: () => context.go('/settings/ai'),
          ),
          const SizedBox(height: 24),

          if (hasOrgs) ...[
            SettingsSectionHeader(title: l10n.settingsOrganization),
            const SizedBox(height: 12),
            _indexTile(
              icon: Icons.business_rounded,
              title: l10n.settingsMyOrg,
              subtitle: l10n.settingsMyOrgSub,
              onTap: () => context.go('/org'),
            ),
            const SizedBox(height: 24),
          ],

          if (isPlatformAdmin) ...[
            SettingsSectionHeader(title: l10n.settingsAdministration),
            const SizedBox(height: 12),
            _indexTile(
              icon: Icons.admin_panel_settings_rounded,
              title: l10n.settingsBackoffice,
              subtitle: l10n.settingsBackofficeSub,
              onTap: () => context.go('/backoffice'),
            ),
            const SizedBox(height: 24),
          ],

          SettingsSectionHeader(title: l10n.settingsAbout),
          const SizedBox(height: 12),
          Card(
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // Brand literal: the expansion the "DuTaTo" acronym is
                  // built from. Translating it would break the acronym, so
                  // it stays in English across locales.
                  Text(
                    'Dumber Than Tomorrow',
                    style: DuTaToTypography.displaySm.copyWith(
                      fontSize: 24,
                      color: context.tokens.ochreDeep,
                      height: 1.1,
                    ),
                  ),
                  const SizedBox(height: 12),
                  Text(
                    l10n.settingsAboutBody,
                    style: context.bodyStyle.copyWith(
                      color: context.tokens.ink2,
                    ),
                  ),
                ],
              ),
            ),
          ),
          const SizedBox(height: 24),

          Center(
            // Brand name + version string — no translatable content.
            child: Text(
              'DuTaTo v0.1.0',
              style: theme.textTheme.labelSmall?.copyWith(
                color: theme.colorScheme.onSurfaceVariant,
              ),
            ),
          ),
          const SizedBox(height: 32),
        ],
      ),
    ),
  );
}