dev
dart 161 lines 6.69 KB
Raw
1 import 'package:cake_wallet/core/address_validator.dart';
2 import 'package:cake_wallet/generated/i18n.dart';
3 import 'package:cake_wallet/new-ui/pages/bridge/bridge_confirm_sheet.dart';
4 import 'package:cake_wallet/new-ui/widgets/keyboard_hide_overlay.dart';
5 import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart';
6 import 'package:cake_wallet/new-ui/widgets/send_page/send_address_input.dart';
7 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
8 import 'package:cake_wallet/view_model/bridge/bridge_view_model.dart';
9 import 'package:flutter/material.dart';
10 import 'package:flutter_mobx/flutter_mobx.dart';
11 import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
12
13 class BridgeReceiveAddressInputPage extends StatefulWidget {
14 const BridgeReceiveAddressInputPage({super.key, required this.bridgeViewModel});
15
16 final BridgeViewModel bridgeViewModel;
17
18 @override
19 State<BridgeReceiveAddressInputPage> createState() => _BridgeReceiveAddressInputPageState();
20 }
21
22 class _BridgeReceiveAddressInputPageState extends State<BridgeReceiveAddressInputPage> {
23 BridgeViewModel get bridgeViewModel => widget.bridgeViewModel;
24
25 late final TextEditingController _controller;
26 final FocusNode _focusNode = FocusNode();
27
28 @override
29 void initState() {
30 super.initState();
31 _controller = TextEditingController();
32 _controller.addListener(() => setState(() {}));
33 }
34
35 @override
36 void dispose() {
37 _controller.dispose();
38 _focusNode.dispose();
39 super.dispose();
40 }
41
42 @override
43 Widget build(BuildContext context) {
44 final theme = Theme.of(context);
45
46 return KeyboardHideOverlay(
47 unfocusOnTap: true,
48 child: Container(
49 decoration: BoxDecoration(
50 color: theme.colorScheme.surface,
51 borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
52 ),
53 child: Column(
54 children: [
55 ModalTopBar(
56 title: 'Input Receive Address',
57 leadingIcon: const Icon(Icons.arrow_back_ios_new, size: 18),
58 leadingSemanticLabel: S.of(context).seed_alert_back,
59 onLeadingPressed: () => Navigator.of(context).pop(),
60 ),
61 SizedBox(height: 48),
62 Expanded(
63 child: SafeArea(
64 child: Padding(
65 padding: const EdgeInsets.symmetric(horizontal: 18),
66 child: Column(
67 crossAxisAlignment: CrossAxisAlignment.stretch,
68 children: [
69 Observer(
70 builder: (_) {
71 final chainName = bridgeViewModel.destinationChainInfo?.name;
72
73 return Column(
74 children: [
75 Text(
76 'Make sure it is compatible with:',
77 textAlign: TextAlign.center,
78 style: theme.textTheme.bodyMedium?.copyWith(
79 color: theme.colorScheme.onSurfaceVariant,
80 fontSize: 14,
81 fontWeight: FontWeight.w400,
82 letterSpacing: -0.07,
83 ),
84 ),
85 const SizedBox(height: 12),
86 Row(
87 mainAxisAlignment: MainAxisAlignment.center,
88 children: [
89 CakeImageWidget(
90 imageUrl:
91 'assets/new-ui/chain_badges/${chainName?.toLowerCase()}.svg',
92 width: 24,
93 height: 24,
94 color: theme.colorScheme.onSurfaceVariant,
95 ),
96 const SizedBox(width: 4),
97 Text(
98 chainName ?? '',
99 style: theme.textTheme.bodyMedium?.copyWith(
100 fontSize: 14,
101 color: theme.colorScheme.onSurfaceVariant,
102 fontWeight: FontWeight.w400,
103 letterSpacing: -0.07,
104 ),
105 ),
106 ],
107 ),
108 ],
109 );
110 },
111 ),
112 const SizedBox(height: 24),
113 NewSendAddressInput(
114 hintText: 'Enter Address',
115 addressController: _controller,
116 focusNode: _focusNode,
117 selectedCurrency: bridgeViewModel.wallet.currency,
118 onEditingComplete: () {},
119 validator:
120 AddressValidator(type: bridgeViewModel.destinationChainInfo!.currency),
121 ),
122 const Spacer(),
123 Observer(
124 builder: (_) {
125 return FilledButton(
126 onPressed: () {
127 final overlayCtx = Navigator.of(context).overlay?.context;
128 bridgeViewModel.setRecipientAddress(_controller.text.trim());
129
130 WidgetsBinding.instance.addPostFrameCallback((_) {
131 if (overlayCtx != null && overlayCtx.mounted) {
132 showMaterialModalBottomSheet<void>(
133 context: overlayCtx,
134 backgroundColor: Colors.transparent,
135 builder: (ctx) => BridgeConfirmSheet(bridgeViewModel),
136 );
137 }
138 });
139 },
140 style: FilledButton.styleFrom(
141 padding: const EdgeInsets.all(16),
142 shape: RoundedRectangleBorder(
143 borderRadius: BorderRadius.circular(18),
144 ),
145 ),
146 child: Text(S.of(context).continue_text),
147 );
148 },
149 ),
150 const SizedBox(height: 12),
151 ],
152 ),
153 ),
154 ),
155 ),
156 ],
157 ),
158 ),
159 );
160 }
161 }