calorimeter/lib/utils/theme_switcher_button.dart

26 lines
681 B
Dart
Raw Normal View History

2024-09-06 11:48:56 +00:00
import 'package:calodiary/utils/theme_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ThemeSwitcherButton extends StatelessWidget {
const ThemeSwitcherButton({
super.key,
});
@override
Widget build(BuildContext context) {
return BlocBuilder<ThemeDataBloc, ThemeState>(builder: (context, state) {
var icon = const Icon(Icons.light_mode);
if (state.brightness == 'light') {
icon = const Icon(Icons.dark_mode);
}
return IconButton(
icon: icon,
onPressed: () {
context.read<ThemeDataBloc>().add(ThemeToggleEvent());
},
);
});
}
}