toggle_switch.dart

Open source file
1import 'package:flutter/widgets.dart';23import '../tokens/design_tokens.dart';4/// Toggle switch defined by toggle-switch.json. State is controlled by the caller.5class ToggleSwitch extends StatelessWidget {6  const ToggleSwitch({7    super.key,8    required this.tokens,9    required this.isOn,10    this.onTap,11  });1213  final DesignTokens tokens;14  final bool isOn;15  final VoidCallback? onTap;1617  @override18  Widget build(BuildContext context) {19    return GestureDetector(20      onTap: onTap,21      behavior: HitTestBehavior.opaque,22      child: AnimatedContainer(23        // Implementation detail: transition duration is not specified in JSON.24        duration: const Duration(milliseconds: 150),25        width: 100,26        height: 56,27        padding: EdgeInsets.all(tokens.space(4)),28        decoration: BoxDecoration(29          color: isOn ? tokens.accent : tokens.muted,30          borderRadius: BorderRadius.circular(tokens.radiusPill),31        ),32        child: Align(33          alignment: isOn ? Alignment.centerRight : Alignment.centerLeft,34          child: Container(35            width: 48,36            height: 48,37            decoration: BoxDecoration(38              shape: BoxShape.circle,39              color: tokens.ink,40            ),41          ),42        ),43      ),44    );45  }46}47