Skip to content

Commit

Permalink
Align CupertinoTextField with Align widget
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmc committed Jun 20, 2019
1 parent 4944950 commit d21f322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/flutter/lib/src/cupertino/text_field.dart
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart' show TextAlignVertical;

import 'colors.dart';
import 'icons.dart';
Expand Down Expand Up @@ -174,6 +175,7 @@ class CupertinoTextField extends StatefulWidget {
this.style,
this.strutStyle,
this.textAlign = TextAlign.start,
this.textAlignVertical = TextAlignVertical.top, // TODO(justinmc): Match previous behavior of if prefix then center
this.readOnly = false,
this.showCursor,
this.autofocus = false,
Expand Down Expand Up @@ -323,6 +325,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.textAlign}
final TextAlign textAlign;

/// {@macro flutter.material.inputDecorator.textAlignVertical}
final TextAlignVertical textAlignVertical;

/// {@macro flutter.widgets.editableText.readOnly}
final bool readOnly;

Expand Down Expand Up @@ -487,6 +492,8 @@ class CupertinoTextField extends StatefulWidget {
properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled'));
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: TextAlign.start));
properties.add(DiagnosticsProperty<TextAlignVertical>('textAlignVertical', textAlignVertical, defaultValue: null));
}
}

Expand Down Expand Up @@ -722,7 +729,10 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
widget.clearButtonMode == OverlayVisibilityMode.never &&
widget.prefix == null &&
widget.suffix == null) {
return editableText;
return Align(
alignment: Alignment(-1.0, widget.textAlignVertical.y),
child: editableText,
);
}

// Otherwise, listen to the current state of the text entry.
Expand Down Expand Up @@ -789,7 +799,13 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
);
}

return Row(children: rowChildren);
return Align(
alignment: Alignment(-1.0, widget.textAlignVertical.y),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: rowChildren,
),
);
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/material/input_decorator.dart
Expand Up @@ -3537,6 +3537,8 @@ class InputDecorationTheme extends Diagnosticable {
/// See also:
///
/// * [TextField.textAlignVertical], which is passed on to the [InputDecorator].
/// * [CupertinoTextField.textAlignVertical], which behaves in the same way as
/// the parameter in TextField.
/// * [InputDecorator.textAlignVertical], which defines the alignment of
/// prefix, input, and suffix, within the [InputDecorator].
class TextAlignVertical {
Expand Down

0 comments on commit d21f322

Please sign in to comment.