Initial commit

This commit is contained in:
jahongireshonqulov
2025-10-18 09:40:06 +05:00
commit 1bf3e41abe
352 changed files with 16315 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import '../../injector_container.dart';
import '../local_source/local_source.dart';
import '../theme/app_theme.dart';
part 'app_event.dart';
part 'app_state.dart';
class AppBloc extends Bloc<AppEvent, AppState> {
AppBloc()
: super(
AppState(
lightTheme: lightThemes.values.first,
darkTheme: darkThemes.values.first,
themeMode: ThemeMode.values.byName(sl<LocalSource>().getThemeMode()),
appLocale: sl<LocalSource>().getLocale(),
),
) {
on<AppThemeSwitchLight>(_switchToLightHandler);
on<AppThemeSwitchDark>(_switchToDarkHandler);
on<AppChangeLocale>(_changeLocale);
}
void _changeLocale(AppChangeLocale event, Emitter<AppState> emit) {
sl<LocalSource>().setLocale(event.appLocale);
emit(state.copyWith(appLocale: event.appLocale));
}
void _switchToLightHandler(
AppThemeSwitchLight event,
Emitter<AppState> emit,
) {
sl<LocalSource>().setThemeMode(ThemeMode.light.name);
emit(
state.copyWith(lightTheme: event.lightTheme, themeMode: ThemeMode.light),
);
}
void _switchToDarkHandler(AppThemeSwitchDark event, Emitter<AppState> emit) {
sl<LocalSource>().setThemeMode(ThemeMode.dark.name);
emit(state.copyWith(darkTheme: event.darkTheme, themeMode: ThemeMode.dark));
}
}

View File

@@ -0,0 +1,32 @@
part of 'app_bloc.dart';
sealed class AppEvent extends Equatable {
const AppEvent();
}
final class AppThemeSwitchLight extends AppEvent {
final ThemeData lightTheme;
const AppThemeSwitchLight({required this.lightTheme});
@override
List<Object?> get props => [lightTheme];
}
final class AppThemeSwitchDark extends AppEvent {
final ThemeData darkTheme;
const AppThemeSwitchDark({required this.darkTheme});
@override
List<Object?> get props => [darkTheme];
}
final class AppChangeLocale extends AppEvent {
final String appLocale;
const AppChangeLocale(this.appLocale);
@override
List<Object?> get props => [appLocale];
}

View File

@@ -0,0 +1,37 @@
part of 'app_bloc.dart';
class AppState extends Equatable {
final ThemeData? lightTheme;
final ThemeData? darkTheme;
final ThemeMode? themeMode;
final String appLocale;
const AppState({
required this.appLocale,
this.lightTheme,
this.darkTheme,
this.themeMode,
});
AppState copyWith({
ThemeData? lightTheme,
ThemeData? darkTheme,
ThemeMode? themeMode,
String? appLocale,
}) {
return AppState(
lightTheme: lightTheme ?? this.lightTheme,
darkTheme: darkTheme ?? this.darkTheme,
themeMode: themeMode ?? this.themeMode,
appLocale: appLocale ?? this.appLocale,
);
}
@override
List<Object?> get props => [
lightTheme,
darkTheme,
themeMode,
appLocale,
];
}