// widgets/ds/ds_switch.dart — 原型 atoms.css .switch 的 Flutter 对照(2026-07-07 登记)。 // 38×22 pill 轨道 + 18px 圆点滑块:on=primary / off=border / disabled 45% 透明。 // 用于布尔即时生效场景(库存⇄在售挂售切换);不同于 Material Switch 的尺寸与配色。 import 'package:flutter/material.dart'; import '../../core/theme/context_tokens.dart'; class DsSwitch extends StatelessWidget { final bool value; final ValueChanged? onChanged; // null = disabled const DsSwitch({super.key, required this.value, this.onChanged}); @override Widget build(BuildContext context) { final t = context.tokens; final enabled = onChanged != null; return Semantics( toggled: value, button: true, child: GestureDetector( onTap: enabled ? () => onChanged!(!value) : null, child: Opacity( opacity: enabled ? 1 : .45, child: AnimatedContainer( duration: const Duration(milliseconds: 180), width: 38, height: 22, padding: const EdgeInsets.all(2), decoration: BoxDecoration( color: value ? t.primary : t.border, borderRadius: BorderRadius.circular(999), ), child: AnimatedAlign( duration: const Duration(milliseconds: 180), curve: Curves.easeOut, alignment: value ? Alignment.centerRight : Alignment.centerLeft, child: Container( width: 18, height: 18, decoration: BoxDecoration( color: t.surface, shape: BoxShape.circle, boxShadow: [ BoxShadow( color: t.shadow, blurRadius: 3, offset: const Offset(0, 1)), ], ), ), ), ), ), ), ); } }