| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter/services.dart'; |
| 5 | import 'package:flutter_svg/flutter_svg.dart'; |
| 6 | |
| 7 | class LightningSwitcher extends StatelessWidget { |
| 8 | const LightningSwitcher( |
| 9 | {super.key, required this.lightningMode, required this.onLightningSwitchPress}); |
| 10 | |
| 11 | final bool lightningMode; |
| 12 | final VoidCallback onLightningSwitchPress; |
| 13 | |
| 14 | @override |
| 15 | Widget build(BuildContext context) { |
| 16 | // One toggle node: the knob position and the coloured glyphs are the only |
| 17 | // visual cue for which mode is active. |
| 18 | return Semantics( |
| 19 | button: true, |
| 20 | toggled: lightningMode, |
| 21 | label: S.of(context).lightning_mode, |
| 22 | child: SizedBox( |
| 23 | child: InkWell( |
| 24 | onTap: () { |
| 25 | HapticFeedback.mediumImpact(); |
| 26 | onLightningSwitchPress(); |
| 27 | }, |
| 28 | child: Container( |
| 29 | decoration: ShapeDecoration( |
| 30 | shape: |
| 31 | RoundedSuperellipseBorder(borderRadius: BorderRadiusGeometry.circular(900.0)), |
| 32 | color: Theme.of(context).colorScheme.surfaceContainer), |
| 33 | width: 70, |
| 34 | height: 36, |
| 35 | padding: EdgeInsets.symmetric(vertical: 2), |
| 36 | child: Stack( |
| 37 | children: [ |
| 38 | AnimatedContainer( |
| 39 | alignment: Alignment.centerRight, |
| 40 | margin: EdgeInsets.only(left: lightningMode ? 36 : 2), |
| 41 | duration: Duration(milliseconds: 250), |
| 42 | curve: Curves.easeOutCubic, |
| 43 | width: 32, |
| 44 | height: 32, |
| 45 | // height: double.infinity, |
| 46 | decoration: BoxDecoration( |
| 47 | borderRadius: BorderRadius.all(Radius.circular(9999990.0)), |
| 48 | color: Theme.of(context).colorScheme.primary), |
| 49 | ), |
| 50 | Container( |
| 51 | child: Row( |
| 52 | spacing: 2.0, |
| 53 | children: [ |
| 54 | SizedBox(), |
| 55 | AnimatedSwitcher( |
| 56 | duration: Duration(milliseconds: 150), |
| 57 | transitionBuilder: (child, animation) => |
| 58 | FadeTransition(opacity: animation, child: child), |
| 59 | child: CakeImageWidget( |
| 60 | imageUrl: 'assets/new-ui/switcher-bitcoin.svg', |
| 61 | key: ValueKey(lightningMode), |
| 62 | width: 32, |
| 63 | height: 32, |
| 64 | colorFilter: ColorFilter.mode( |
| 65 | lightningMode |
| 66 | ? Theme.of(context).colorScheme.primary |
| 67 | : Theme.of(context).colorScheme.surfaceContainer, |
| 68 | BlendMode.srcIn, |
| 69 | ), |
| 70 | ), |
| 71 | ), |
| 72 | AnimatedSwitcher( |
| 73 | duration: Duration(milliseconds: 150), |
| 74 | transitionBuilder: (child, animation) => |
| 75 | FadeTransition(opacity: animation, child: child), |
| 76 | child: CakeImageWidget( |
| 77 | imageUrl: 'assets/new-ui/switcher-lightning.svg', |
| 78 | key: ValueKey(lightningMode), |
| 79 | width: 32, |
| 80 | height: 32, |
| 81 | colorFilter: ColorFilter.mode( |
| 82 | lightningMode |
| 83 | ? Theme.of(context).colorScheme.surfaceContainer |
| 84 | : Theme.of(context).colorScheme.primary, |
| 85 | BlendMode.srcIn, |
| 86 | ), |
| 87 | ), |
| 88 | ), |
| 89 | ], |
| 90 | ), |
| 91 | ), |
| 92 | ], |
| 93 | ), |
| 94 | ), |
| 95 | ), |
| 96 | ), |
| 97 | ); |
| 98 | } |
| 99 | } |