theme_switch_widget.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import 'package:adaptive_theme/adaptive_theme.dart';
  2. import 'package:animated_toggle_switch/animated_toggle_switch.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:photos/ente_theme_data.dart';
  5. class ThemeSwitchWidget extends StatelessWidget {
  6. const ThemeSwitchWidget({Key key}) : super(key: key);
  7. @override
  8. Widget build(BuildContext context) {
  9. var selectedTheme = 0;
  10. if (Theme.of(context).brightness == Brightness.dark) {
  11. selectedTheme = 1;
  12. }
  13. return AnimatedToggleSwitch<int>.rolling(
  14. current: selectedTheme,
  15. values: const [0, 1],
  16. onChanged: (i) {
  17. debugPrint("Changed to {i}, selectedTheme is {selectedTheme} ");
  18. if (i == 0) {
  19. AdaptiveTheme.of(context).setLight();
  20. } else {
  21. AdaptiveTheme.of(context).setDark();
  22. }
  23. },
  24. iconBuilder: (i, size, foreground) {
  25. final color = selectedTheme == i
  26. ? Theme.of(context).colorScheme.themeSwitchActiveIconColor
  27. : Theme.of(context).colorScheme.themeSwitchInactiveIconColor;
  28. if (i == 0) {
  29. return Icon(
  30. Icons.light_mode,
  31. color: color,
  32. );
  33. } else {
  34. return Icon(
  35. Icons.dark_mode,
  36. color: color,
  37. );
  38. }
  39. },
  40. height: 36,
  41. indicatorSize: Size(36, 36),
  42. indicatorColor: Theme.of(context).colorScheme.themeSwitchIndicatorColor,
  43. borderColor: Theme.of(context)
  44. .colorScheme
  45. .themeSwitchInactiveIconColor
  46. .withOpacity(0.1),
  47. borderWidth: 1,
  48. );
  49. }
  50. }