@@ -25,8 +25,6 @@ import 'theme.dart';
2525
2626export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
2727
28- enum _TextFieldType { material, adaptive }
29-
3028/// Signature for the [TextField.buildCounter] callback.
3129typedef InputCounterWidgetBuilder = Widget ? Function (
3230 /// The build context for the TextField.
@@ -382,8 +380,7 @@ class TextField extends StatefulWidget {
382380 this .scrollPhysics,
383381 this .autofillHints,
384382 this .restorationId,
385- }) : _textFieldType = _TextFieldType .material,
386- assert (textAlign != null ),
383+ }) : assert (textAlign != null ),
387384 assert (readOnly != null ),
388385 assert (autofocus != null ),
389386 assert (obscuringCharacter != null && obscuringCharacter.length == 1 ),
@@ -430,119 +427,6 @@ class TextField extends StatefulWidget {
430427 )),
431428 super (key: key);
432429
433- /// Creates a [CupertinoTextField] if the target platform is iOS, creates a
434- /// material design text field otherwise.
435- ///
436- /// To retain the standard look of [CupertinoTextField] , this constructor only
437- /// uses the [decoration] property's [decoration.hintText] ,
438- /// [decoration.hintStyle] , [decoration.suffix] , and [decoration.prefix] for
439- /// the iOS platform, and all else is ignored in support of the default iOS
440- /// look. For instance, the [decoration.border] cannot override the default
441- /// iOS-style border.
442- ///
443- /// The target platform is based on the current [Theme] : [ThemeData.platform] .
444- const TextField .adaptive ({
445- Key ? key,
446- this .controller,
447- this .focusNode,
448- this .decoration = const InputDecoration (),
449- TextInputType ? keyboardType,
450- this .textInputAction,
451- this .textCapitalization = TextCapitalization .none,
452- this .style,
453- this .strutStyle,
454- this .textAlign = TextAlign .start,
455- this .textAlignVertical,
456- this .textDirection,
457- this .readOnly = false ,
458- ToolbarOptions ? toolbarOptions,
459- this .showCursor,
460- this .autofocus = false ,
461- this .obscuringCharacter = '•' ,
462- this .obscureText = false ,
463- this .autocorrect = true ,
464- SmartDashesType ? smartDashesType,
465- SmartQuotesType ? smartQuotesType,
466- this .enableSuggestions = true ,
467- this .maxLines = 1 ,
468- this .minLines,
469- this .expands = false ,
470- this .maxLength,
471- this .maxLengthEnforced = true ,
472- this .onChanged,
473- this .onEditingComplete,
474- this .onSubmitted,
475- this .onAppPrivateCommand,
476- this .inputFormatters,
477- this .enabled,
478- this .cursorWidth = 2.0 ,
479- this .cursorHeight,
480- this .cursorRadius,
481- this .cursorColor,
482- this .selectionControls,
483- this .selectionHeightStyle = ui.BoxHeightStyle .tight,
484- this .selectionWidthStyle = ui.BoxWidthStyle .tight,
485- this .keyboardAppearance,
486- this .scrollPadding = const EdgeInsets .all (20.0 ),
487- this .dragStartBehavior = DragStartBehavior .start,
488- this .enableInteractiveSelection = true ,
489- this .onTap,
490- this .mouseCursor,
491- this .buildCounter,
492- this .scrollController,
493- this .scrollPhysics,
494- this .autofillHints,
495- this .restorationId,
496- }) : _textFieldType = _TextFieldType .adaptive,
497- assert (textAlign != null ),
498- assert (readOnly != null ),
499- assert (autofocus != null ),
500- assert (obscuringCharacter != null && obscuringCharacter.length == 1 ),
501- assert (obscureText != null ),
502- assert (autocorrect != null ),
503- smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType .disabled : SmartDashesType .enabled),
504- smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType .disabled : SmartQuotesType .enabled),
505- assert (enableSuggestions != null ),
506- assert (enableInteractiveSelection != null ),
507- assert (maxLengthEnforced != null ),
508- assert (scrollPadding != null ),
509- assert (dragStartBehavior != null ),
510- assert (selectionHeightStyle != null ),
511- assert (selectionWidthStyle != null ),
512- assert (maxLines == null || maxLines > 0 ),
513- assert (minLines == null || minLines > 0 ),
514- assert (
515- (maxLines == null ) || (minLines == null ) || (maxLines >= minLines),
516- "minLines can't be greater than maxLines" ,
517- ),
518- assert (expands != null ),
519- assert (
520- ! expands || (maxLines == null && minLines == null ),
521- 'minLines and maxLines must be null when expands is true.' ,
522- ),
523- assert (! obscureText || maxLines == 1 , 'Obscured fields cannot be multiline.' ),
524- assert (maxLength == null || maxLength == TextField .noMaxLength || maxLength > 0 ),
525- // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
526- assert (! identical (textInputAction, TextInputAction .newline) ||
527- maxLines == 1 ||
528- ! identical (keyboardType, TextInputType .text),
529- 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.' ),
530- keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType .text : TextInputType .multiline),
531- toolbarOptions = toolbarOptions ?? (obscureText ?
532- const ToolbarOptions (
533- selectAll: true ,
534- paste: true ,
535- ) :
536- const ToolbarOptions (
537- copy: true ,
538- cut: true ,
539- selectAll: true ,
540- paste: true ,
541- )),
542- super (key: key);
543-
544- final _TextFieldType _textFieldType;
545-
546430 /// Controls the text being edited.
547431 ///
548432 /// If null, this widget will create its own [TextEditingController] .
@@ -1192,60 +1076,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
11921076 }
11931077 }
11941078
1195- Widget _buildCupertinoTextField (BuildContext context) {
1196- return CupertinoTextField (
1197- key: widget.key,
1198- controller: widget.controller,
1199- focusNode: widget.focusNode,
1200- placeholder: widget.decoration? .hintText,
1201- placeholderStyle: widget.decoration? .hintStyle ?? const TextStyle (fontWeight: FontWeight .w400, color: CupertinoColors .placeholderText),
1202- prefix: widget.decoration? .prefix,
1203- suffix: widget.decoration? .suffix,
1204- keyboardType: widget.keyboardType,
1205- textInputAction: widget.textInputAction,
1206- textCapitalization: widget.textCapitalization,
1207- style: widget.style,
1208- strutStyle: widget.strutStyle,
1209- textAlign: widget.textAlign,
1210- textAlignVertical: widget.textAlignVertical,
1211- readOnly: widget.readOnly,
1212- toolbarOptions: widget.toolbarOptions,
1213- showCursor: widget.showCursor,
1214- autofocus: widget.autofocus,
1215- obscuringCharacter: widget.obscuringCharacter,
1216- obscureText: widget.obscureText,
1217- autocorrect: widget.autocorrect,
1218- smartDashesType: widget.smartDashesType,
1219- smartQuotesType: widget.smartQuotesType,
1220- enableSuggestions: widget.enableSuggestions,
1221- maxLines: widget.maxLines,
1222- minLines: widget.minLines,
1223- expands: widget.expands,
1224- maxLength: widget.maxLength,
1225- maxLengthEnforced: widget.maxLengthEnforced,
1226- onChanged: widget.onChanged,
1227- onEditingComplete: widget.onEditingComplete,
1228- onSubmitted: widget.onSubmitted,
1229- inputFormatters: widget.inputFormatters,
1230- enabled: widget.enabled,
1231- cursorWidth: widget.cursorWidth,
1232- cursorHeight: widget.cursorHeight,
1233- cursorColor: widget.cursorColor,
1234- selectionHeightStyle: widget.selectionHeightStyle,
1235- selectionWidthStyle: widget.selectionWidthStyle,
1236- keyboardAppearance: widget.keyboardAppearance,
1237- scrollPadding: widget.scrollPadding,
1238- dragStartBehavior: widget.dragStartBehavior,
1239- enableInteractiveSelection: widget.enableInteractiveSelection,
1240- onTap: widget.onTap,
1241- scrollController: widget.scrollController,
1242- scrollPhysics: widget.scrollPhysics,
1243- autofillHints: widget.autofillHints,
1244- restorationId: widget.restorationId,
1245- );
1246- }
1247-
1248- Widget _buildMaterialTextField (BuildContext context) {
1079+ @override
1080+ Widget build (BuildContext context) {
12491081 assert (debugCheckHasMaterial (context));
12501082 assert (debugCheckHasMaterialLocalizations (context));
12511083 assert (debugCheckHasDirectionality (context));
@@ -1424,27 +1256,4 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
14241256 ),
14251257 );
14261258 }
1427-
1428- @override
1429- Widget build (BuildContext context) {
1430- switch (widget._textFieldType) {
1431- case _TextFieldType .material:
1432- return _buildMaterialTextField (context);
1433-
1434- case _TextFieldType .adaptive: {
1435- final ThemeData theme = Theme .of (context);
1436- assert (theme.platform != null );
1437- switch (theme.platform) {
1438- case TargetPlatform .iOS:
1439- case TargetPlatform .macOS:
1440- return _buildCupertinoTextField (context);
1441- case TargetPlatform .android:
1442- case TargetPlatform .fuchsia:
1443- case TargetPlatform .linux:
1444- case TargetPlatform .windows:
1445- return _buildMaterialTextField (context);
1446- }
1447- }
1448- }
1449- }
14501259}
0 commit comments