20 lines
742 B
Dart
20 lines
742 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:pmu/components/locale/l10n/app_locale.dart';
|
|
import 'package:pmu/presentation/locale/events.dart';
|
|
import 'package:pmu/presentation/locale/state.dart';
|
|
|
|
class LocaleBloc extends Bloc<LocaleEvent, LocaleState> {
|
|
LocaleBloc(Locale defaultLocale)
|
|
: super(LocaleState(currentLocale: defaultLocale)) {
|
|
on<ChangeLocaleEvent>(_onChangeLocale);
|
|
}
|
|
|
|
Future<void> _onChangeLocale(
|
|
ChangeLocaleEvent event, Emitter<LocaleState> emit) async {
|
|
final toChange = AppLocale.supportedLocales
|
|
.firstWhere((e) => e.languageCode != state.currentLocale.languageCode);
|
|
emit(state.copyWith(currentLocale: toChange));
|
|
}
|
|
}
|