PMU_Puchkina_A.A_PIbd-32/lib/presentation/locale_bloc/locale_bloc.dart

19 lines
754 B
Dart

import 'dart:async';
import 'dart:ui';
import 'package:app/components/locale/l10n/app_locale.dart';
import 'package:app/presentation/locale_bloc/locale_events.dart';
import 'package:app/presentation/locale_bloc/locale_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class LocaleBloc extends Bloc<LocaleEvent, LocaleState> {
LocaleBloc(Locale defaultLocale) : super(LocaleState(currentLocale: defaultLocale)) {
on<ChangeLocaleEvent>(_onChangeLocale);
}
FutureOr<void> _onChangeLocale(ChangeLocaleEvent event, Emitter<LocaleState> emit) async {
final toChange = AppLocale.supportedLocales
.firstWhere((e) => e.languageCode != state.currentLocale.languageCode);
emit(state.copyWith(currentLocale: toChange));
}
}