| 1 | import 'package:cake_wallet/themes/core/theme_extension.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | |
| 4 | class StandardSwitch extends StatefulWidget { |
| 5 | const StandardSwitch({ |
| 6 | required this.value, |
| 7 | required this.onTapped, |
| 8 | this.backgroundColor, |
| 9 | }); |
| 10 | |
| 11 | final bool value; |
| 12 | final Color? backgroundColor; |
| 13 | final VoidCallback onTapped; |
| 14 | @override |
| 15 | StandardSwitchState createState() => StandardSwitchState(); |
| 16 | } |
| 17 | |
| 18 | class StandardSwitchState extends State<StandardSwitch> { |
| 19 | @override |
| 20 | Widget build(BuildContext context) { |
| 21 | return Semantics( |
| 22 | toggled: widget.value, |
| 23 | child: GestureDetector( |
| 24 | onTap: widget.onTapped, |
| 25 | child: AnimatedContainer( |
| 26 | padding: EdgeInsets.only(left: 2.0, right: 2.0), |
| 27 | alignment: widget.value ? Alignment.centerRight : Alignment.centerLeft, |
| 28 | duration: Duration(milliseconds: 250), |
| 29 | width: 50, |
| 30 | height: 28, |
| 31 | decoration: BoxDecoration( |
| 32 | color: widget.value |
| 33 | ? Theme.of(context).colorScheme.primary |
| 34 | : widget.backgroundColor ?? context.currentTheme.customColors.toggleColorOffState, |
| 35 | borderRadius: BorderRadius.all(Radius.circular(14.0)), |
| 36 | ), |
| 37 | child: Container( |
| 38 | width: 24.0, |
| 39 | height: 24.0, |
| 40 | decoration: BoxDecoration( |
| 41 | color: context.currentTheme.isDark |
| 42 | ? Theme.of(context).colorScheme.surface |
| 43 | : context.currentTheme.customColors.toggleKnobStateColor, |
| 44 | shape: BoxShape.circle, |
| 45 | ), |
| 46 | ), |
| 47 | ), |
| 48 | ), |
| 49 | ); |
| 50 | } |
| 51 | } |