| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; |
| 3 | import 'package:cake_wallet/typography.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter/services.dart'; |
| 6 | |
| 7 | class EnterAmountWidget extends StatelessWidget { |
| 8 | const EnterAmountWidget( |
| 9 | {required this.minValue, |
| 10 | required this.maxValue, |
| 11 | required this.fiatCurrency, |
| 12 | required this.amountFieldFocus, |
| 13 | required this.amountController, |
| 14 | required this.onAmountChanged}); |
| 15 | |
| 16 | final String minValue; |
| 17 | final String maxValue; |
| 18 | final String fiatCurrency; |
| 19 | final FocusNode amountFieldFocus; |
| 20 | final TextEditingController amountController; |
| 21 | final Function(String) onAmountChanged; |
| 22 | |
| 23 | @override |
| 24 | Widget build(BuildContext context) { |
| 25 | return Container( |
| 26 | height: MediaQuery.of(context).size.height * 0.1, |
| 27 | child: Column( |
| 28 | crossAxisAlignment: CrossAxisAlignment.start, |
| 29 | children: [ |
| 30 | Spacer(flex: 1), |
| 31 | Text( |
| 32 | S.of(context).enter_amount, |
| 33 | style: Theme.of(context).textTheme.titleLarge!, |
| 34 | ), |
| 35 | Container( |
| 36 | decoration: BoxDecoration( |
| 37 | border: Border( |
| 38 | bottom: BorderSide( |
| 39 | width: 1.0, color: Theme.of(context).colorScheme.onSurfaceVariant))), |
| 40 | child: BaseTextFormField( |
| 41 | isDense: true, |
| 42 | contentPadding: EdgeInsets.zero, |
| 43 | controller: amountController, |
| 44 | keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true), |
| 45 | hintText: '0.00', |
| 46 | maxLines: 1, |
| 47 | prefixIcon: Padding( |
| 48 | padding: const EdgeInsets.only(top: 2.0), |
| 49 | child: Text( |
| 50 | '$fiatCurrency: ', |
| 51 | style: Theme.of(context).textTheme.titleMedium!, |
| 52 | ), |
| 53 | ), |
| 54 | prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0), |
| 55 | suffixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0), |
| 56 | suffixIcon: Padding( |
| 57 | padding: const EdgeInsets.only(top: 2, right: 4), |
| 58 | child: Row( |
| 59 | mainAxisSize: MainAxisSize.min, |
| 60 | children: [ |
| 61 | Text('QTY ', style: Theme.of(context).textTheme.titleMedium!), |
| 62 | Text('1', |
| 63 | style: Theme.of(context) |
| 64 | .textTheme |
| 65 | .titleMedium! |
| 66 | .copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant)), |
| 67 | ], |
| 68 | ), |
| 69 | ), |
| 70 | textStyle: Theme.of(context).textTheme.titleMedium!, |
| 71 | placeholderTextStyle: Theme.of(context) |
| 72 | .textTheme |
| 73 | .titleMedium! |
| 74 | .copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant), |
| 75 | inputFormatters: [ |
| 76 | FilteringTextInputFormatter.deny(RegExp('[\-|\ ]')), |
| 77 | FilteringTextInputFormatter.allow( |
| 78 | RegExp(r'^\d+(\.|\,)?\d{0,2}'), |
| 79 | ), |
| 80 | ], |
| 81 | ), |
| 82 | ), |
| 83 | const SizedBox(height: 4), |
| 84 | Row( |
| 85 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 86 | children: [ |
| 87 | Text(S.of(context).min_amount(minValue) + ' $fiatCurrency', |
| 88 | style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 89 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 90 | )), |
| 91 | Text(S.of(context).max_amount(maxValue) + ' $fiatCurrency', |
| 92 | style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 93 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 94 | )), |
| 95 | ], |
| 96 | ), |
| 97 | Spacer(flex: 1), |
| 98 | ], |
| 99 | ), |
| 100 | ); |
| 101 | } |
| 102 | } |