| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | |
| 5 | class MobileExchangeCardsSection extends StatelessWidget { |
| 6 | final Widget firstExchangeCard; |
| 7 | final Widget secondExchangeCard; |
| 8 | final bool isBuySellOption; |
| 9 | final VoidCallback? onBuyTap; |
| 10 | final VoidCallback? onSellTap; |
| 11 | |
| 12 | const MobileExchangeCardsSection({ |
| 13 | Key? key, |
| 14 | required this.firstExchangeCard, |
| 15 | required this.secondExchangeCard, |
| 16 | this.isBuySellOption = false, |
| 17 | this.onBuyTap, |
| 18 | this.onSellTap, |
| 19 | }) : super(key: key); |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext context) { |
| 23 | return Container( |
| 24 | padding: EdgeInsets.only(bottom: isBuySellOption ? 16 : 16), |
| 25 | decoration: BoxDecoration( |
| 26 | borderRadius: BorderRadius.only( |
| 27 | bottomLeft: Radius.circular(24), |
| 28 | bottomRight: Radius.circular(24), |
| 29 | ), |
| 30 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 31 | ), |
| 32 | child: Column( |
| 33 | children: <Widget>[ |
| 34 | Container( |
| 35 | decoration: BoxDecoration( |
| 36 | borderRadius: BorderRadius.only( |
| 37 | bottomLeft: Radius.circular(24), |
| 38 | bottomRight: Radius.circular(24), |
| 39 | ), |
| 40 | color: Theme.of(context).colorScheme.surfaceContainerHigh, |
| 41 | ), |
| 42 | padding: EdgeInsets.fromLTRB(24, 105, 24, 24), |
| 43 | child: Column( |
| 44 | children: [ |
| 45 | if (isBuySellOption) |
| 46 | Column( |
| 47 | children: [ |
| 48 | const SizedBox(height: 16), |
| 49 | BuySellOptionButtons(onBuyTap: onBuyTap, onSellTap: onSellTap), |
| 50 | ], |
| 51 | ), |
| 52 | firstExchangeCard, |
| 53 | ], |
| 54 | ), |
| 55 | ), |
| 56 | Padding( |
| 57 | padding: EdgeInsets.only(top: 20, left: 24, right: 24), |
| 58 | child: secondExchangeCard, |
| 59 | ) |
| 60 | ], |
| 61 | ), |
| 62 | ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | class BuySellOptionButtons extends StatefulWidget { |
| 67 | final VoidCallback? onBuyTap; |
| 68 | final VoidCallback? onSellTap; |
| 69 | |
| 70 | const BuySellOptionButtons({this.onBuyTap, this.onSellTap}); |
| 71 | |
| 72 | @override |
| 73 | _BuySellOptionButtonsState createState() => _BuySellOptionButtonsState(); |
| 74 | } |
| 75 | |
| 76 | class _BuySellOptionButtonsState extends State<BuySellOptionButtons> { |
| 77 | bool isBuySelected = true; |
| 78 | |
| 79 | @override |
| 80 | Widget build(BuildContext context) { |
| 81 | return Padding( |
| 82 | padding: const EdgeInsets.only(bottom: 24), |
| 83 | child: Row( |
| 84 | children: [ |
| 85 | Expanded(flex: 2, child: SizedBox()), |
| 86 | Expanded( |
| 87 | flex: 5, |
| 88 | child: SelectButton( |
| 89 | center: true, |
| 90 | height: 44, |
| 91 | text: S.of(context).buy, |
| 92 | isSelected: isBuySelected, |
| 93 | showTrailingIcon: false, |
| 94 | textColor: isBuySelected |
| 95 | ? Theme.of(context).colorScheme.onPrimary |
| 96 | : Theme.of(context).colorScheme.onSecondaryContainer, |
| 97 | padding: EdgeInsets.only(left: 50, right: 30), |
| 98 | color: isBuySelected |
| 99 | ? Theme.of(context).colorScheme.primary |
| 100 | : Theme.of(context).colorScheme.surfaceContainer, |
| 101 | onTap: () { |
| 102 | setState(() => isBuySelected = true); |
| 103 | if (widget.onBuyTap != null) widget.onBuyTap!(); |
| 104 | }, |
| 105 | ), |
| 106 | ), |
| 107 | Expanded(child: const SizedBox()), |
| 108 | Expanded( |
| 109 | flex: 5, |
| 110 | child: SelectButton( |
| 111 | center: true, |
| 112 | height: 44, |
| 113 | text: S.of(context).sell, |
| 114 | isSelected: !isBuySelected, |
| 115 | showTrailingIcon: false, |
| 116 | textColor: !isBuySelected |
| 117 | ? Theme.of(context).colorScheme.onPrimary |
| 118 | : Theme.of(context).colorScheme.onSecondaryContainer, |
| 119 | padding: EdgeInsets.only(left: 50, right: 30), |
| 120 | color: !isBuySelected |
| 121 | ? Theme.of(context).colorScheme.primary |
| 122 | : Theme.of(context).colorScheme.surfaceContainer, |
| 123 | onTap: () { |
| 124 | setState(() => isBuySelected = false); |
| 125 | if (widget.onSellTap != null) widget.onSellTap!(); |
| 126 | }, |
| 127 | ), |
| 128 | ), |
| 129 | Expanded(flex: 2, child: SizedBox()), |
| 130 | ], |
| 131 | ), |
| 132 | ); |
| 133 | } |
| 134 | } |