settings_widgets.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'package:flutter/material.dart';
  2. import '../../core/theme/app_colors.dart';
  3. /// Shared Settings switch styling so each card matches the rest of the page.
  4. class SettingsSwitch extends StatelessWidget {
  5. const SettingsSwitch({
  6. super.key,
  7. required this.value,
  8. required this.onChanged,
  9. required this.semanticsLabel,
  10. this.enabled = true,
  11. });
  12. final bool value;
  13. final ValueChanged<bool> onChanged;
  14. final String semanticsLabel;
  15. final bool enabled;
  16. @override
  17. Widget build(BuildContext context) {
  18. final colors = context.colors;
  19. return Semantics(
  20. label: semanticsLabel,
  21. child: Switch(
  22. value: value,
  23. onChanged: enabled ? onChanged : null,
  24. thumbColor: WidgetStateProperty.resolveWith<Color?>((states) {
  25. if (states.contains(WidgetState.disabled)) {
  26. return colors.inkFaint.withValues(alpha: 0.45);
  27. }
  28. return states.contains(WidgetState.selected)
  29. ? colors.accentInk
  30. : colors.inkFaint;
  31. }),
  32. trackColor: WidgetStateProperty.resolveWith<Color?>((states) {
  33. if (states.contains(WidgetState.disabled)) {
  34. return colors.surfaceStrong.withValues(alpha: 0.5);
  35. }
  36. return states.contains(WidgetState.selected)
  37. ? colors.accent
  38. : colors.surfaceStrong;
  39. }),
  40. trackOutlineColor: WidgetStatePropertyAll(
  41. colors.border.withValues(alpha: enabled ? 1 : 0.5),
  42. ),
  43. ),
  44. );
  45. }
  46. }