build method

  1. @override
Widget build(
  1. BuildContext context,
  2. WidgetRef ref,
  3. Locale state,
  4. LanguageSwitcherNotifier notifier,
  5. List<LocaleInfo> supportedLocales,
)
override

Build method that concrete implementations must override.

This method receives all necessary data for building language switcher UI:

  • context: The build context for accessing theme and navigation
  • ref: WidgetRef for accessing Riverpod providers
  • state: Current locale state from the language switcher provider
  • notifier: LanguageSwitcherNotifier for changing locales
  • supportedLocales: List of all supported locales from app configuration

Example implementation:

@override
Widget build(
  BuildContext context,
  WidgetRef ref,
  Locale state,
  LanguageSwitcherNotifier notifier,
  List<LocaleInfo> supportedLocales,
) {
  return Column(
    children: supportedLocales.map((localeInfo) {
      return RadioListTile<Locale>(
        value: localeInfo.locale,
        groupValue: state,
        title: Text(localeInfo.displayName),
        onChanged: (locale) {
          if (locale != null) notifier.changeLocale(locale);
        },
      );
    }).toList(),
  );
}

Implementation

@override
Widget build(
  BuildContext context,
  WidgetRef ref,
  Locale state,
  LanguageSwitcherNotifier notifier,
  List<LocaleInfo> supportedLocales,
) {
  final localeInfo = supportedLocales.firstWhere(
    (info) => info.locale.languageCode == state.languageCode,
  );

  return IconButton(
    onPressed: () {
      HapticFeedback.lightImpact();
      LanguageSwitcher.show(context);
    },
    icon: Stack(
      children: [
        const Icon(Icons.language),
        Positioned(
          right: 0,
          bottom: 0,
          child: Container(
            padding: const EdgeInsets.all(2),
            decoration: BoxDecoration(
              color: Theme.of(context).colorScheme.primary,
              shape: BoxShape.circle,
            ),
            child: Text(
              localeInfo.locale.languageCode.toUpperCase(),
              style: TextStyle(
                color: Theme.of(context).colorScheme.onPrimary,
                fontSize: 8,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ],
    ),
    tooltip: context.jetI10n.changeLanguage,
  );
}