| 1 | import 'package:cake_wallet/src/widgets/primary_button.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/standard_slide_button_widget.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | |
| 5 | enum FooterType { none, slideActionButton, singleActionButton, doubleActionButton } |
| 6 | |
| 7 | abstract class BaseBottomSheet extends StatelessWidget { |
| 8 | const BaseBottomSheet({ |
| 9 | super.key, |
| 10 | required this.titleText, |
| 11 | this.titleIconPath, |
| 12 | required this.footerType, |
| 13 | this.slideActionButtonText, |
| 14 | this.onSlideActionComplete, |
| 15 | this.isSlideActionEnabled = true, |
| 16 | this.singleActionButtonText, |
| 17 | this.accessibleNavigationModeSlideActionButtonText, |
| 18 | this.onSingleActionButtonPressed, |
| 19 | this.singleActionButtonKey, |
| 20 | this.doubleActionLeftButtonText, |
| 21 | this.doubleActionRightButtonText, |
| 22 | this.onLeftActionButtonPressed, |
| 23 | this.onRightActionButtonPressed, |
| 24 | this.leftActionButtonKey, |
| 25 | this.rightActionButtonKey, |
| 26 | required this.maxHeight, |
| 27 | }); |
| 28 | |
| 29 | final String titleText; |
| 30 | final String? titleIconPath; |
| 31 | final FooterType footerType; |
| 32 | final String? slideActionButtonText; |
| 33 | final VoidCallback? onSlideActionComplete; |
| 34 | final bool isSlideActionEnabled; |
| 35 | final String? singleActionButtonText; |
| 36 | final String? accessibleNavigationModeSlideActionButtonText; |
| 37 | final VoidCallback? onSingleActionButtonPressed; |
| 38 | final Key? singleActionButtonKey; |
| 39 | final String? doubleActionLeftButtonText; |
| 40 | final String? doubleActionRightButtonText; |
| 41 | final VoidCallback? onLeftActionButtonPressed; |
| 42 | final VoidCallback? onRightActionButtonPressed; |
| 43 | final Key? leftActionButtonKey; |
| 44 | final Key? rightActionButtonKey; |
| 45 | final double maxHeight; |
| 46 | |
| 47 | Widget contentWidget(BuildContext context); |
| 48 | |
| 49 | @override |
| 50 | Widget build(BuildContext context) { |
| 51 | return ConstrainedBox( |
| 52 | constraints: BoxConstraints(maxHeight: maxHeight), |
| 53 | child: ClipRRect( |
| 54 | borderRadius: const BorderRadius.only( |
| 55 | topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0)), |
| 56 | child: Container( |
| 57 | color: Theme.of(context).colorScheme.surface, |
| 58 | child: SafeArea( |
| 59 | child: Column( |
| 60 | mainAxisSize: MainAxisSize.min, |
| 61 | children: <Widget>[ |
| 62 | _buildHeader(context), |
| 63 | contentWidget(context), |
| 64 | _buildFooter(context), |
| 65 | ], |
| 66 | ), |
| 67 | ), |
| 68 | ), |
| 69 | ), |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | Widget _buildHeader(BuildContext context) => Column( |
| 74 | children: [ |
| 75 | const SizedBox(height: 12), |
| 76 | Container( |
| 77 | width: 64, |
| 78 | height: 5, |
| 79 | decoration: BoxDecoration( |
| 80 | borderRadius: BorderRadius.circular(4), |
| 81 | color: Theme.of(context).colorScheme.onSurface, |
| 82 | ), |
| 83 | ), |
| 84 | const SizedBox(height: 20), |
| 85 | Row( |
| 86 | mainAxisAlignment: MainAxisAlignment.center, |
| 87 | children: [ |
| 88 | if (titleIconPath != null) ...[ |
| 89 | Image.asset(titleIconPath!, height: 24, width: 24), |
| 90 | const SizedBox(width: 6), |
| 91 | ], |
| 92 | Text( |
| 93 | titleText, |
| 94 | style: Theme.of(context).textTheme.titleLarge!.copyWith( |
| 95 | fontSize: 20, |
| 96 | fontWeight: FontWeight.w600, |
| 97 | decoration: TextDecoration.none, |
| 98 | ), |
| 99 | ), |
| 100 | ], |
| 101 | ), |
| 102 | const SizedBox(height: 13), |
| 103 | ], |
| 104 | ); |
| 105 | |
| 106 | Widget _buildFooter(BuildContext context) { |
| 107 | switch (footerType) { |
| 108 | case FooterType.none: |
| 109 | return const SizedBox.shrink(); |
| 110 | |
| 111 | case FooterType.slideActionButton: |
| 112 | return Padding( |
| 113 | padding: const EdgeInsets.fromLTRB(40, 12, 40, 24), |
| 114 | child: StandardSlideButton( |
| 115 | key: ValueKey('base_bottom_sheet_widget_standard_slide_button_key'), |
| 116 | buttonText: slideActionButtonText ?? '', |
| 117 | onSlideComplete: onSlideActionComplete ?? () {}, |
| 118 | accessibleNavigationModeButtonText: accessibleNavigationModeSlideActionButtonText ?? '', |
| 119 | isDisabled: !isSlideActionEnabled, |
| 120 | ), |
| 121 | ); |
| 122 | |
| 123 | case FooterType.singleActionButton: |
| 124 | return Padding( |
| 125 | padding: const EdgeInsets.fromLTRB(16, 12, 16, 24), |
| 126 | child: LoadingPrimaryButton( |
| 127 | key: singleActionButtonKey, |
| 128 | text: singleActionButtonText ?? '', |
| 129 | onPressed: onSingleActionButtonPressed ?? () {}, |
| 130 | color: Theme.of(context).colorScheme.primary, |
| 131 | textColor: Theme.of(context).colorScheme.onPrimary, |
| 132 | isLoading: false, |
| 133 | isDisabled: false, |
| 134 | ), |
| 135 | ); |
| 136 | |
| 137 | case FooterType.doubleActionButton: |
| 138 | return Padding( |
| 139 | padding: const EdgeInsets.fromLTRB(16, 0, 16, 24), |
| 140 | child: Row( |
| 141 | children: [ |
| 142 | Expanded( |
| 143 | child: PrimaryButton( |
| 144 | key: leftActionButtonKey, |
| 145 | text: doubleActionLeftButtonText ?? '', |
| 146 | onPressed: onLeftActionButtonPressed, |
| 147 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 148 | textColor: Theme.of(context).colorScheme.onSecondaryContainer), |
| 149 | ), |
| 150 | const SizedBox(width: 12), |
| 151 | Expanded( |
| 152 | child: PrimaryButton( |
| 153 | key: rightActionButtonKey, |
| 154 | text: doubleActionRightButtonText ?? '', |
| 155 | onPressed: onRightActionButtonPressed, |
| 156 | color: Theme.of(context).colorScheme.primary, |
| 157 | textColor: Theme.of(context).colorScheme.onPrimary, |
| 158 | ), |
| 159 | ), |
| 160 | ], |
| 161 | ), |
| 162 | ); |
| 163 | } |
| 164 | } |
| 165 | } |