1
- import 'package:flutter/cupertino.dart' ;
2
1
import 'package:flutter/material.dart' ;
3
2
4
3
import '/core/models/editor_configs/pro_image_editor_configs.dart' ;
@@ -27,8 +26,6 @@ class RoundedBackgroundTextField extends StatefulWidget {
27
26
this .hint,
28
27
this .hintStyle,
29
28
this .autofocus = false ,
30
- this .showSelectionHandles = false ,
31
- this .onSelectionChanged,
32
29
this .onChanged,
33
30
this .onEditingComplete,
34
31
this .onSubmitted,
@@ -62,9 +59,6 @@ class RoundedBackgroundTextField extends StatefulWidget {
62
59
/// {@macro flutter.widgets.editableText.autofocus}
63
60
final bool autofocus;
64
61
65
- /// Whether to show selection handles.
66
- final bool showSelectionHandles;
67
-
68
62
/// {@macro flutter.widgets.editableText.cursorWidth}
69
63
final double cursorWidth;
70
64
@@ -87,9 +81,6 @@ class RoundedBackgroundTextField extends StatefulWidget {
87
81
/// {@macro flutter.widgets.editableText.onSubmitted}
88
82
final ValueChanged <String >? onSubmitted;
89
83
90
- /// {@macro flutter.widgets.editableText.onSelectionChanged}
91
- final SelectionChangedCallback ? onSelectionChanged;
92
-
93
84
@override
94
85
State <RoundedBackgroundTextField > createState () =>
95
86
_RoundedBackgroundTextFieldState ();
@@ -100,8 +91,6 @@ class _RoundedBackgroundTextFieldState
100
91
late final _textController = widget.controller;
101
92
final _scrollCtrl = ScrollController ();
102
93
103
- final _padding = const EdgeInsets .all (6.0 );
104
-
105
94
@override
106
95
void initState () {
107
96
super .initState ();
@@ -141,10 +130,7 @@ class _RoundedBackgroundTextFieldState
141
130
TextAlign .center || _ => Alignment .topCenter,
142
131
},
143
132
children: [
144
- if (_textController.text.isNotEmpty)
145
- _buildBackgroundText ()
146
- else if (widget.hint != null )
147
- _buildHint (fontSize: fontSize),
133
+ if (_textController.text.isNotEmpty) _buildBackgroundText (),
148
134
_buildEditableText (fontSize: fontSize),
149
135
],
150
136
);
@@ -177,131 +163,53 @@ class _RoundedBackgroundTextFieldState
177
163
}
178
164
179
165
Widget _buildEditableText ({required double fontSize}) {
180
- final theme = Theme .of (context);
181
- final selectionTheme = TextSelectionTheme .of (context);
182
- TextSelectionControls ? textSelectionControls;
183
- final bool paintCursorAboveText;
184
- final bool cursorOpacityAnimates;
185
- Offset ? cursorOffset;
186
- final Color selectionColor;
187
- Color ? autocorrectionTextRectColor;
188
- Radius ? cursorRadius = widget.cursorRadius;
189
-
190
- switch (theme.platform) {
191
- case TargetPlatform .iOS:
192
- final cupertinoTheme = CupertinoTheme .of (context);
193
- textSelectionControls ?? = cupertinoTextSelectionControls;
194
- paintCursorAboveText = true ;
195
- cursorOpacityAnimates = true ;
196
- selectionColor = selectionTheme.selectionColor ??
197
- cupertinoTheme.primaryColor.withValues (alpha: 0.40 );
198
- cursorRadius ?? = const Radius .circular (2.0 );
199
- cursorOffset = Offset (
200
- iOSHorizontalOffset / MediaQuery .devicePixelRatioOf (context), 0 );
201
- autocorrectionTextRectColor = selectionColor;
202
- break ;
203
-
204
- case TargetPlatform .macOS:
205
- final cupertinoTheme = CupertinoTheme .of (context);
206
- textSelectionControls ?? = cupertinoDesktopTextSelectionControls;
207
- paintCursorAboveText = true ;
208
- cursorOpacityAnimates = true ;
209
- selectionColor = selectionTheme.selectionColor ??
210
- cupertinoTheme.primaryColor.withValues (alpha: 0.40 );
211
- cursorRadius ?? = const Radius .circular (2.0 );
212
- cursorOffset = Offset (
213
- iOSHorizontalOffset / MediaQuery .devicePixelRatioOf (context), 0 );
214
- break ;
215
-
216
- case TargetPlatform .android:
217
- case TargetPlatform .fuchsia:
218
- textSelectionControls ?? = materialTextSelectionControls;
219
- paintCursorAboveText = false ;
220
- cursorOpacityAnimates = false ;
221
- selectionColor = selectionTheme.selectionColor ??
222
- theme.colorScheme.primary.withValues (alpha: 0.40 );
223
- break ;
224
-
225
- case TargetPlatform .linux:
226
- case TargetPlatform .windows:
227
- textSelectionControls ?? = desktopTextSelectionControls;
228
- paintCursorAboveText = false ;
229
- cursorOpacityAnimates = false ;
230
- selectionColor = selectionTheme.selectionColor ??
231
- theme.colorScheme.primary.withValues (alpha: 0.40 );
232
- break ;
233
- }
234
-
235
- return Padding (
236
- padding: EdgeInsets .zero,
237
- child: Listener (
238
- behavior: HitTestBehavior .translucent,
239
- onPointerDown: _textController.text.isEmpty
240
- ? (_) {
241
- if (View .of (context).viewInsets.bottom <= 0 ) {
242
- FocusManager .instance.primaryFocus? .unfocus ();
243
- widget.focusNode.requestFocus ();
244
- }
166
+ return Material (
167
+ type: MaterialType .transparency,
168
+ child: TextField (
169
+ onTap: _textController.text.isEmpty &&
170
+ View .of (context).viewInsets.bottom <= 0
171
+ ? () {
172
+ FocusManager .instance.primaryFocus? .unfocus ();
173
+ widget.focusNode.requestFocus ();
245
174
}
246
175
: null ,
247
- child: EditableText (
248
- autofocus: widget.autofocus,
249
- controller: _textController,
250
- focusNode: widget.focusNode,
251
- scrollPhysics: const NeverScrollableScrollPhysics (),
252
- scrollController: _scrollCtrl,
253
- scrollPadding: EdgeInsets .zero,
254
- style: widget.style.copyWith (
255
- fontSize: fontSize,
256
- leadingDistribution: TextLeadingDistribution .proportional,
257
- ),
258
- textAlign: widget.textAlign,
259
- maxLines: null ,
260
- keyboardType: TextInputType .multiline,
261
- backgroundCursorColor: CupertinoColors .inactiveGray,
262
- cursorColor: widget.configs.style.inputCursorColor,
263
- cursorWidth: widget.cursorWidth,
264
- cursorHeight: widget.cursorHeight,
265
- cursorRadius: widget.cursorRadius,
266
- paintCursorAboveText: paintCursorAboveText,
267
- cursorOpacityAnimates: cursorOpacityAnimates,
268
- cursorOffset: cursorOffset,
269
- autocorrectionTextRectColor: autocorrectionTextRectColor,
270
- textCapitalization: TextCapitalization .sentences,
271
- enableInteractiveSelection: true ,
272
- selectionColor: selectionColor,
273
- selectionControls: textSelectionControls,
274
- showSelectionHandles: widget.showSelectionHandles,
275
- showCursor: true ,
276
- autocorrect: widget.configs.enableAutocorrect,
277
- smartDashesType: SmartDashesType .enabled,
278
- smartQuotesType: SmartQuotesType .enabled,
279
- enableSuggestions: widget.configs.enableSuggestions,
280
- clipBehavior: Clip .hardEdge,
281
- textInputAction: TextInputAction .newline,
282
- onSelectionChanged: widget.onSelectionChanged,
283
- magnifierConfiguration: const TextMagnifierConfiguration (),
284
- onChanged: widget.onChanged,
285
- onEditingComplete: widget.onEditingComplete,
286
- onSubmitted: widget.onSubmitted,
176
+ autofocus: widget.autofocus,
177
+ controller: _textController,
178
+ focusNode: widget.focusNode,
179
+ scrollPhysics: const NeverScrollableScrollPhysics (),
180
+ scrollController: _scrollCtrl,
181
+ scrollPadding: EdgeInsets .zero,
182
+ style: widget.style.copyWith (
183
+ fontSize: fontSize,
184
+ leadingDistribution: TextLeadingDistribution .proportional,
185
+ height: 0.0 ,
287
186
),
288
- ),
289
- );
290
- }
291
-
292
- Widget _buildHint ({required double fontSize}) {
293
- final style =
294
- (widget.hintStyle ?? TextStyle (color: Theme .of (context).hintColor))
295
- .copyWith (fontSize: fontSize);
296
-
297
- return Positioned (
298
- child: Padding (
299
- padding: _padding,
300
- child: Text (
301
- widget.hint! ,
302
- style: style,
303
- textAlign: widget.textAlign,
187
+ decoration: InputDecoration .collapsed (
188
+ hintText: _textController.text.isEmpty ? widget.hint : '' ,
189
+ hintStyle: (widget.hintStyle ??
190
+ TextStyle (color: Theme .of (context).hintColor))
191
+ .copyWith (fontSize: fontSize),
192
+ maintainHintSize: false ,
304
193
),
194
+ textAlign: widget.textAlign,
195
+ maxLines: null ,
196
+ keyboardType: TextInputType .multiline,
197
+ textCapitalization: TextCapitalization .sentences,
198
+ textInputAction: TextInputAction .newline,
199
+ cursorColor: widget.configs.style.inputCursorColor,
200
+ cursorWidth: widget.cursorWidth,
201
+ cursorHeight: widget.cursorHeight,
202
+ cursorRadius: widget.cursorRadius,
203
+ enableInteractiveSelection: true ,
204
+ showCursor: true ,
205
+ autocorrect: widget.configs.enableAutocorrect,
206
+ smartDashesType: SmartDashesType .enabled,
207
+ smartQuotesType: SmartQuotesType .enabled,
208
+ enableSuggestions: widget.configs.enableSuggestions,
209
+ clipBehavior: Clip .hardEdge,
210
+ onChanged: widget.onChanged,
211
+ onEditingComplete: widget.onEditingComplete,
212
+ onSubmitted: widget.onSubmitted,
305
213
),
306
214
);
307
215
}
0 commit comments