import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:pmu_labworks/components/locale/l10n/app_locale.dart'; import 'package:pmu_labworks/view/locale_bloc/locale_events.dart'; import 'package:pmu_labworks/view/locale_bloc/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((e) => e.languageCode != state.currentLocale.languageCode); emit(state.copyWith(currentLocale: toChange)); } }