| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import 'package:flutter/material.dart';
- import '../../core/theme/app_colors.dart';
- /// Shared Settings switch styling so each card matches the rest of the page.
- class SettingsSwitch extends StatelessWidget {
- const SettingsSwitch({
- super.key,
- required this.value,
- required this.onChanged,
- required this.semanticsLabel,
- this.enabled = true,
- });
- final bool value;
- final ValueChanged<bool> onChanged;
- final String semanticsLabel;
- final bool enabled;
- @override
- Widget build(BuildContext context) {
- final colors = context.colors;
- return Semantics(
- label: semanticsLabel,
- child: Switch(
- value: value,
- onChanged: enabled ? onChanged : null,
- thumbColor: WidgetStateProperty.resolveWith<Color?>((states) {
- if (states.contains(WidgetState.disabled)) {
- return colors.inkFaint.withValues(alpha: 0.45);
- }
- return states.contains(WidgetState.selected)
- ? colors.accentInk
- : colors.inkFaint;
- }),
- trackColor: WidgetStateProperty.resolveWith<Color?>((states) {
- if (states.contains(WidgetState.disabled)) {
- return colors.surfaceStrong.withValues(alpha: 0.5);
- }
- return states.contains(WidgetState.selected)
- ? colors.accent
- : colors.surfaceStrong;
- }),
- trackOutlineColor: WidgetStatePropertyAll(
- colors.border.withValues(alpha: enabled ? 1 : 0.5),
- ),
- ),
- );
- }
- }
|