|
1 | 1 | import 'package:bb_mobile/core/themes/app_theme.dart'; |
2 | | -import 'package:bb_mobile/core/widgets/inputs/amount_input_formatter.dart'; |
3 | 2 | import 'package:bb_mobile/core/widgets/text/text.dart'; |
4 | 3 | import 'package:flutter/material.dart'; |
5 | 4 |
|
@@ -99,136 +98,3 @@ class DialPad extends StatelessWidget { |
99 | 98 | ); |
100 | 99 | } |
101 | 100 | } |
102 | | - |
103 | | -/// DialPad widget for amount entry with built-in formatting |
104 | | -class AmountDialPad extends StatelessWidget { |
105 | | - const AmountDialPad({ |
106 | | - super.key, |
107 | | - required this.controller, |
108 | | - required this.inputCurrencyCode, |
109 | | - this.disableFeedback = false, |
110 | | - this.onAmountChanged, |
111 | | - }); |
112 | | - |
113 | | - final TextEditingController controller; |
114 | | - final String inputCurrencyCode; |
115 | | - final bool disableFeedback; |
116 | | - final VoidCallback? onAmountChanged; |
117 | | - |
118 | | - void _handleNumberPressed(String number) { |
119 | | - final formatter = AmountInputFormatter(inputCurrencyCode); |
120 | | - final currentValue = controller.value; |
121 | | - final selectionStart = currentValue.selection.baseOffset; |
122 | | - final selectionEnd = currentValue.selection.extentOffset; |
123 | | - final currentText = currentValue.text; |
124 | | - |
125 | | - // Build new text by inserting/replacing at selection |
126 | | - final String newText; |
127 | | - final int newCursorPos; |
128 | | - |
129 | | - if (selectionStart == -1) { |
130 | | - // Field is not focused, add to end |
131 | | - newText = currentText + number; |
132 | | - newCursorPos = newText.length; |
133 | | - } else if (selectionStart == selectionEnd) { |
134 | | - // No selection, insert at cursor |
135 | | - newText = |
136 | | - currentText.substring(0, selectionStart) + |
137 | | - number + |
138 | | - currentText.substring(selectionStart); |
139 | | - newCursorPos = selectionStart + number.length; |
140 | | - } else { |
141 | | - // Replace selection |
142 | | - newText = |
143 | | - currentText.substring(0, selectionStart) + |
144 | | - number + |
145 | | - currentText.substring(selectionEnd); |
146 | | - newCursorPos = selectionStart + number.length; |
147 | | - } |
148 | | - |
149 | | - // Apply formatter (it handles cursor positioning) |
150 | | - final formattedValue = formatter.formatEditUpdate( |
151 | | - currentValue, |
152 | | - TextEditingValue( |
153 | | - text: newText, |
154 | | - selection: TextSelection.collapsed(offset: newCursorPos), |
155 | | - ), |
156 | | - ); |
157 | | - |
158 | | - if (formattedValue.text != currentText) { |
159 | | - controller.value = formattedValue; |
160 | | - onAmountChanged?.call(); |
161 | | - } |
162 | | - } |
163 | | - |
164 | | - void _handleBackspacePressed() { |
165 | | - final formatter = AmountInputFormatter(inputCurrencyCode); |
166 | | - final currentValue = controller.value; |
167 | | - final selectionStart = currentValue.selection.baseOffset; |
168 | | - final selectionEnd = currentValue.selection.extentOffset; |
169 | | - final currentText = currentValue.text; |
170 | | - |
171 | | - // Build new text by removing at selection |
172 | | - final String newText; |
173 | | - final int newCursorPos; |
174 | | - |
175 | | - if (selectionStart == -1) { |
176 | | - // Field is not focused, remove from end |
177 | | - newText = |
178 | | - currentText.isNotEmpty |
179 | | - ? currentText.substring(0, currentText.length - 1) |
180 | | - : currentText; |
181 | | - newCursorPos = newText.length; |
182 | | - } else if (selectionStart == selectionEnd) { |
183 | | - // No selection, remove before cursor |
184 | | - if (selectionStart > 0) { |
185 | | - newText = |
186 | | - currentText.substring(0, selectionStart - 1) + |
187 | | - currentText.substring(selectionStart); |
188 | | - newCursorPos = selectionStart - 1; |
189 | | - } else { |
190 | | - newText = currentText; |
191 | | - newCursorPos = 0; |
192 | | - } |
193 | | - } else { |
194 | | - // Remove selection |
195 | | - newText = |
196 | | - currentText.substring(0, selectionStart) + |
197 | | - currentText.substring(selectionEnd); |
198 | | - newCursorPos = selectionStart; |
199 | | - } |
200 | | - |
201 | | - // Apply formatter (it handles cursor positioning) |
202 | | - final formattedValue = formatter.formatEditUpdate( |
203 | | - currentValue, |
204 | | - TextEditingValue( |
205 | | - text: newText, |
206 | | - selection: TextSelection.collapsed(offset: newCursorPos), |
207 | | - ), |
208 | | - ); |
209 | | - |
210 | | - if (formattedValue.text != currentText) { |
211 | | - controller.value = formattedValue; |
212 | | - onAmountChanged?.call(); |
213 | | - } |
214 | | - } |
215 | | - |
216 | | - @override |
217 | | - Widget build(BuildContext context) { |
218 | | - // Check if decimals are allowed |
219 | | - final decimalPlaces = |
220 | | - inputCurrencyCode == 'sats' |
221 | | - ? 0 |
222 | | - : inputCurrencyCode == 'BTC' |
223 | | - ? 8 |
224 | | - : 2; |
225 | | - final onlyDigits = decimalPlaces == 0; |
226 | | - |
227 | | - return DialPad( |
228 | | - onNumberPressed: _handleNumberPressed, |
229 | | - onBackspacePressed: _handleBackspacePressed, |
230 | | - disableFeedback: disableFeedback, |
231 | | - onlyDigits: onlyDigits, |
232 | | - ); |
233 | | - } |
234 | | -} |
0 commit comments