| 1 | import 'dart:ui'; |
| 2 | |
| 3 | import 'package:cake_wallet/entities/new_ui_entities/list_item/list_item_text_field.dart'; |
| 4 | import 'package:cake_wallet/generated/i18n.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/new_list_row/new_list_section.dart'; |
| 6 | import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart'; |
| 7 | import 'package:flutter/material.dart'; |
| 8 | import 'package:mobx/mobx.dart'; |
| 9 | |
| 10 | class AddressLabelInputPopup extends StatefulWidget { |
| 11 | const AddressLabelInputPopup({ |
| 12 | super.key, |
| 13 | required this.walletAddressEditOrCreateViewModel, |
| 14 | }); |
| 15 | |
| 16 | final WalletAddressEditOrCreateViewModel walletAddressEditOrCreateViewModel; |
| 17 | |
| 18 | @override |
| 19 | State<AddressLabelInputPopup> createState() => _AddressLabelInputPopupState(); |
| 20 | } |
| 21 | |
| 22 | class _AddressLabelInputPopupState extends State<AddressLabelInputPopup> { |
| 23 | late final TextEditingController _controller; |
| 24 | late final FocusNode _focusNode; |
| 25 | |
| 26 | @override |
| 27 | void initState() { |
| 28 | super.initState(); |
| 29 | _controller = TextEditingController(); |
| 30 | _focusNode = FocusNode(); |
| 31 | |
| 32 | reaction((_) => widget.walletAddressEditOrCreateViewModel.state, |
| 33 | (AddressEditOrCreateState state) { |
| 34 | if (state is AddressSavedSuccessfully) { |
| 35 | WidgetsBinding.instance.addPostFrameCallback((_) { |
| 36 | if (mounted) Navigator.of(context).pop(widget.walletAddressEditOrCreateViewModel.label); |
| 37 | }); |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | WidgetsBinding.instance.addPostFrameCallback((_) { |
| 42 | _focusNode.requestFocus(); |
| 43 | _controller.text = widget.walletAddressEditOrCreateViewModel.label; |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | @override |
| 48 | void dispose() { |
| 49 | _controller.dispose(); |
| 50 | _focusNode.dispose(); |
| 51 | super.dispose(); |
| 52 | } |
| 53 | |
| 54 | @override |
| 55 | Widget build(BuildContext context) { |
| 56 | return BackdropFilter( |
| 57 | filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), |
| 58 | child: Column( |
| 59 | mainAxisSize: MainAxisSize.max, |
| 60 | mainAxisAlignment: MainAxisAlignment.spaceAround, |
| 61 | children: [ |
| 62 | Padding( |
| 63 | padding: const EdgeInsets.all(16.0), |
| 64 | child: NewListSections( |
| 65 | sections: { |
| 66 | "": [ |
| 67 | ListItemTextField( |
| 68 | keyValue: "label", |
| 69 | label: S.of(context).label, |
| 70 | focusNode: _focusNode, |
| 71 | onFieldSubmitted: (value) { |
| 72 | widget.walletAddressEditOrCreateViewModel.label = value; |
| 73 | widget.walletAddressEditOrCreateViewModel.save(); |
| 74 | // Navigator.of(context).pop(); |
| 75 | }) |
| 76 | ] |
| 77 | }, |
| 78 | controllers: {"label": _controller}, |
| 79 | ), |
| 80 | ), |
| 81 | ]), |
| 82 | ); |
| 83 | } |
| 84 | } |