calorimeter/lib/utils/theme_switcher_button.dart
2024-12-07 13:39:11 +01:00

28 lines
789 B
Dart

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2024 Marco Groß <mgross@sw-gross.de> */
import 'package:calorimeter/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());
},
);
});
}
}