-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_bloc.dart
55 lines (46 loc) · 1.58 KB
/
app_bloc.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
library app_bloc;
import 'dart:convert';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:frd/data/datasource/local/entities/language_entity.dart';
import 'package:frd/domain/usecases/app_usecase.dart';
part 'app_event.dart';
part 'app_state.dart';
class AppBloc extends Bloc<AppEvent, AppState> {
AppBloc(this._appUseCase) : super(OnInitialState()) {
on<OnAppConfigChangeRequested>(_onAppConfigChangeRequested);
on<OnGetLanguageRequested>(_onGetLanguageRequested);
}
final AppUseCase _appUseCase;
void _onAppConfigChangeRequested(
OnAppConfigChangeRequested event,
Emitter<AppState> emit,
) async {
switch (event.type) {
case AppConfigType.all:
await _appUseCase.updateAppConfig(AppConfigType.all);
return emit(const OnAppConfigChangeState.all());
case AppConfigType.theme:
_appUseCase.updateAppConfig(
AppConfigType.theme,
theme: event.theme,
);
return emit(const OnAppConfigChangeState.theme());
case AppConfigType.locale:
_appUseCase.updateAppConfig(
AppConfigType.locale,
language: event.language,
);
return emit(const OnAppConfigChangeState.locale());
}
}
void _onGetLanguageRequested(
OnGetLanguageRequested event,
Emitter<AppState> emit,
) async {
final data = await rootBundle.loadString('assets/json/languages.json');
final languages = jsonDecode(data);
return emit(OnGetLanguageState(languages));
}
}