j
This commit is contained in:
17
lib/theme/theme_bloc.dart
Normal file
17
lib/theme/theme_bloc.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'theme_events.dart';
|
||||
part 'theme_state.dart';
|
||||
|
||||
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
|
||||
final AppTheme initialAppTheme;
|
||||
ThemeBloc({required this.initialAppTheme})
|
||||
: super(
|
||||
ThemeState(status: ThemeStatus.success, appTheme: initialAppTheme),
|
||||
) {
|
||||
on<ChangeThemeEvent>((event, emit) async {
|
||||
emit(state.copyWith(appTheme: event.appTheme));
|
||||
});
|
||||
}
|
||||
}
|
||||
17
lib/theme/theme_events.dart
Normal file
17
lib/theme/theme_events.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
part of 'theme_bloc.dart';
|
||||
|
||||
abstract class ThemeEvent extends Equatable {
|
||||
const ThemeEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ChangeThemeEvent extends ThemeEvent {
|
||||
const ChangeThemeEvent({required this.appTheme});
|
||||
|
||||
final AppTheme appTheme;
|
||||
|
||||
@override
|
||||
List<Object> get props => [appTheme];
|
||||
}
|
||||
30
lib/theme/theme_state.dart
Normal file
30
lib/theme/theme_state.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
part of 'theme_bloc.dart';
|
||||
|
||||
enum ThemeStatus { initial, success }
|
||||
|
||||
enum AppTheme {
|
||||
dark(name: 'dark'),
|
||||
light(name: 'light'),
|
||||
system(name: 'system');
|
||||
|
||||
final String name;
|
||||
|
||||
const AppTheme({required this.name});
|
||||
}
|
||||
|
||||
class ThemeState extends Equatable {
|
||||
const ThemeState({required this.status, required this.appTheme});
|
||||
|
||||
final ThemeStatus status;
|
||||
final AppTheme appTheme;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, appTheme];
|
||||
|
||||
ThemeState copyWith({ThemeStatus? status, AppTheme? appTheme}) {
|
||||
return ThemeState(
|
||||
status: status ?? this.status,
|
||||
appTheme: appTheme ?? this.appTheme,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user