import 'dart:ui'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../components/locale/l10n/app_localizations.dart'; import 'locale_events.dart'; import 'locale_state.dart'; class LocaleBloc extends Bloc { LocaleBloc(Locale defaultLocale) : super(LocaleState(currentLocale: defaultLocale)) { on(_onChangeLocale); } Future _onChangeLocale( ChangeLocaleEvent event, Emitter emit ) async { final toChange = AppLocale.supportedLocales.firstWhere( (loc) => loc.languageCode != state.currentLocale.languageCode); emit(state.copyWith(currentLocale: toChange)); } }