| 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/view_model/wallet_address_list/wallet_address_list_view_model.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | |
| 6 | class HeaderTile extends StatefulWidget { |
| 7 | HeaderTile({ |
| 8 | required this.title, |
| 9 | required this.walletAddressListViewModel, |
| 10 | this.showSearchButton = false, |
| 11 | this.showTrailingButton = false, |
| 12 | this.trailingButtonTap, |
| 13 | this.onSearchCallback, |
| 14 | this.trailingIcon, |
| 15 | }); |
| 16 | |
| 17 | final String title; |
| 18 | final WalletAddressListViewModel walletAddressListViewModel; |
| 19 | final bool showSearchButton; |
| 20 | final bool showTrailingButton; |
| 21 | final VoidCallback? trailingButtonTap; |
| 22 | final VoidCallback? onSearchCallback; |
| 23 | final Icon? trailingIcon; |
| 24 | |
| 25 | @override |
| 26 | _HeaderTileState createState() => _HeaderTileState(); |
| 27 | } |
| 28 | |
| 29 | class _HeaderTileState extends State<HeaderTile> { |
| 30 | bool _isSearchActive = false; |
| 31 | |
| 32 | @override |
| 33 | Widget build(BuildContext context) { |
| 34 | final searchIcon = Icon(Icons.search, color: Theme.of(context).colorScheme.primary); |
| 35 | |
| 36 | return Container( |
| 37 | padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12), |
| 38 | color: Theme.of(context).colorScheme.surface, |
| 39 | child: Row( |
| 40 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 41 | children: <Widget>[ |
| 42 | _isSearchActive |
| 43 | ? Expanded( |
| 44 | child: BaseTextFormField( |
| 45 | onChanged: (value) { |
| 46 | widget.walletAddressListViewModel.updateSearchText(value); |
| 47 | widget.onSearchCallback?.call(); |
| 48 | }, |
| 49 | cursorColor: Theme.of(context).colorScheme.onSurface, |
| 50 | cursorWidth: 0.5, |
| 51 | isDense: true, |
| 52 | hintText: '${S.of(context).search}...', |
| 53 | contentPadding: EdgeInsets.all(4), |
| 54 | placeholderTextStyle: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 55 | fontSize: 16, |
| 56 | fontWeight: FontWeight.w600, |
| 57 | ), |
| 58 | autofocus: true, |
| 59 | ), |
| 60 | ) |
| 61 | : Text( |
| 62 | widget.title, |
| 63 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 64 | fontSize: 16, |
| 65 | fontWeight: FontWeight.w600, |
| 66 | ), |
| 67 | ), |
| 68 | Row( |
| 69 | children: [ |
| 70 | if (widget.showSearchButton) |
| 71 | GestureDetector( |
| 72 | onTap: () { |
| 73 | setState(() { |
| 74 | _isSearchActive = !_isSearchActive; |
| 75 | widget.walletAddressListViewModel.updateSearchText(''); |
| 76 | }); |
| 77 | }, |
| 78 | child: Container( |
| 79 | height: 32, |
| 80 | width: 32, |
| 81 | decoration: BoxDecoration( |
| 82 | shape: BoxShape.circle, |
| 83 | color: Theme.of(context).colorScheme.secondaryContainer, |
| 84 | ), |
| 85 | child: searchIcon, |
| 86 | ), |
| 87 | ), |
| 88 | const SizedBox(width: 8), |
| 89 | if (widget.showTrailingButton) |
| 90 | GestureDetector( |
| 91 | onTap: widget.trailingButtonTap, |
| 92 | child: Container( |
| 93 | height: 32, |
| 94 | width: 32, |
| 95 | decoration: BoxDecoration( |
| 96 | shape: BoxShape.circle, |
| 97 | color: Theme.of(context).colorScheme.secondaryContainer, |
| 98 | ), |
| 99 | child: widget.trailingIcon, |
| 100 | ), |
| 101 | ), |
| 102 | ], |
| 103 | ), |
| 104 | ], |
| 105 | ), |
| 106 | ); |
| 107 | } |
| 108 | } |