Commit 72dc7d91 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Revert "Fixes InputDecorator to work with textScaleFactor, fixes Material...

Revert "Fixes InputDecorator to work with textScaleFactor, fixes Material Design differences. (#12595)" (#12678)

This reverts commit 67cf7918.

Reverting because this causes scuba regressions that I'd like to
address in another PR that is pending, but we'd like to roll Flutter.
parent ce4a4577
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart' show debugDumpRenderTree; import 'package:flutter/rendering.dart' show debugDumpRenderTree;
...@@ -33,11 +31,6 @@ class CardCollectionState extends State<CardCollection> { ...@@ -33,11 +31,6 @@ class CardCollectionState extends State<CardCollection> {
static const double kCardMargins = 8.0; static const double kCardMargins = 8.0;
static const double kFixedCardHeight = 100.0; static const double kFixedCardHeight = 100.0;
static const List<double> _cardHeights = const <double>[
48.0, 63.0, 85.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 85.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 85.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
];
MaterialColor _primaryColor = Colors.deepPurple; MaterialColor _primaryColor = Colors.deepPurple;
List<CardModel> _cardModels; List<CardModel> _cardModels;
...@@ -48,22 +41,15 @@ class CardCollectionState extends State<CardCollection> { ...@@ -48,22 +41,15 @@ class CardCollectionState extends State<CardCollection> {
bool _sunshine = false; bool _sunshine = false;
bool _varyFontSizes = false; bool _varyFontSizes = false;
void _updateCardSizes() {
if (_fixedSizeCards)
return;
_cardModels = new List<CardModel>.generate(
_cardModels.length,
(int i) {
_cardModels[i].height = _editable ? max(_cardHeights[i], 60.0) : _cardHeights[i];
return _cardModels[i];
}
);
}
void _initVariableSizedCardModels() { void _initVariableSizedCardModels() {
final List<double> cardHeights = <double>[
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
];
_cardModels = new List<CardModel>.generate( _cardModels = new List<CardModel>.generate(
_cardHeights.length, cardHeights.length,
(int i) => new CardModel(i, _editable ? max(_cardHeights[i], 60.0) : _cardHeights[i]) (int i) => new CardModel(i, cardHeights[i])
); );
} }
...@@ -140,7 +126,6 @@ class CardCollectionState extends State<CardCollection> { ...@@ -140,7 +126,6 @@ class CardCollectionState extends State<CardCollection> {
void _toggleEditable() { void _toggleEditable() {
setState(() { setState(() {
_editable = !_editable; _editable = !_editable;
_updateCardSizes();
}); });
} }
......
...@@ -371,12 +371,6 @@ class InputDecorator extends StatelessWidget { ...@@ -371,12 +371,6 @@ class InputDecorator extends StatelessWidget {
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
final Widget child; final Widget child;
static const double _kBottomBorderHeight = 1.0;
static const double _kDensePadding = 4.0;
static const double _kNormalPadding = 8.0;
static const double _kDenseTopPadding = 8.0;
static const double _kNormalTopPadding = 16.0;
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder description) { void debugFillProperties(DiagnosticPropertiesBuilder description) {
super.debugFillProperties(description); super.debugFillProperties(description);
...@@ -398,23 +392,32 @@ class InputDecorator extends StatelessWidget { ...@@ -398,23 +392,32 @@ class InputDecorator extends StatelessWidget {
return themeData.hintColor; return themeData.hintColor;
} }
Widget _buildContent(Color borderColor, double topPadding, bool isDense, Widget inputChild, double subTextHeight) { Widget _buildContent(Color borderColor, double topPadding, bool isDense, Widget inputChild) {
final double bottomPadding = isDense ? 8.0 : 1.0;
const double bottomBorder = 2.0;
final double bottomHeight = isDense ? 14.0 : 18.0;
final EdgeInsets padding = new EdgeInsets.only(top: topPadding, bottom: bottomPadding);
final EdgeInsets margin = new EdgeInsets.only(bottom: bottomHeight - (bottomPadding + bottomBorder));
if (decoration.hideDivider) { if (decoration.hideDivider) {
return new Container( return new Container(
padding: new EdgeInsets.only(top: topPadding, bottom: _kNormalPadding), margin: margin + const EdgeInsets.only(bottom: bottomBorder),
padding: padding,
child: inputChild, child: inputChild,
); );
} }
return new AnimatedContainer( return new AnimatedContainer(
padding: new EdgeInsets.only(top: topPadding, bottom: _kNormalPadding - _kBottomBorderHeight), margin: margin,
padding: padding,
duration: _kTransitionDuration, duration: _kTransitionDuration,
curve: _kTransitionCurve, curve: _kTransitionCurve,
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border( border: new Border(
bottom: new BorderSide( bottom: new BorderSide(
color: borderColor, color: borderColor,
width: _kBottomBorderHeight, width: bottomBorder,
), ),
), ),
), ),
...@@ -426,7 +429,6 @@ class InputDecorator extends StatelessWidget { ...@@ -426,7 +429,6 @@ class InputDecorator extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
final ThemeData themeData = Theme.of(context); final ThemeData themeData = Theme.of(context);
final double textScaleFactor = MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1.0;
final bool isDense = decoration.isDense; final bool isDense = decoration.isDense;
final bool isCollapsed = decoration.isCollapsed; final bool isCollapsed = decoration.isCollapsed;
...@@ -437,37 +439,34 @@ class InputDecorator extends StatelessWidget { ...@@ -437,37 +439,34 @@ class InputDecorator extends StatelessWidget {
final String hintText = decoration.hintText; final String hintText = decoration.hintText;
final String errorText = decoration.errorText; final String errorText = decoration.errorText;
// If we're not focused, there's no value, and labelText was provided,
// then the label appears where the hint would. And we will not show
// the hintText.
final bool hasInlineLabel = !isFocused && labelText != null && isEmpty;
final Color activeColor = _getActiveColor(themeData);
final TextStyle baseStyle = this.baseStyle ?? themeData.textTheme.subhead; final TextStyle baseStyle = this.baseStyle ?? themeData.textTheme.subhead;
final TextStyle hintStyle = decoration.hintStyle ?? baseStyle.copyWith(color: themeData.hintColor); final TextStyle hintStyle = decoration.hintStyle ?? baseStyle.copyWith(color: themeData.hintColor);
final TextStyle subtextStyle = errorText != null
? decoration.errorStyle ?? themeData.textTheme.caption.copyWith(color: themeData.errorColor)
: decoration.helperStyle ?? themeData.textTheme.caption.copyWith(color: themeData.hintColor);
final double entryTextHeight = baseStyle.fontSize * textScaleFactor; final Color activeColor = _getActiveColor(themeData);
final double subTextHeight = subtextStyle.fontSize * textScaleFactor;
double topPadding = isCollapsed ? 0.0 : (isDense ? _kDenseTopPadding : _kNormalTopPadding); double topPadding = isCollapsed ? 0.0 : (isDense ? 12.0 : 16.0);
final List<Widget> stackChildren = <Widget>[]; final List<Widget> stackChildren = <Widget>[];
// If we're not focused, there's no value, and labelText was provided,
// then the label appears where the hint would. And we will not show
// the hintText.
final bool hasInlineLabel = !isFocused && labelText != null && isEmpty;
if (labelText != null) { if (labelText != null) {
assert(!isCollapsed); assert(!isCollapsed);
final TextStyle floatingLabelStyle = decoration.labelStyle ?? themeData.textTheme.caption.copyWith(color: activeColor); final TextStyle labelStyle = hasInlineLabel ?
final TextStyle labelStyle = hasInlineLabel ? hintStyle : floatingLabelStyle; hintStyle : (decoration.labelStyle ?? themeData.textTheme.caption.copyWith(color: activeColor));
final double labelTextHeight = floatingLabelStyle.fontSize * textScaleFactor;
final double topPaddingIncrement = themeData.textTheme.caption.fontSize + (isDense ? 4.0 : 8.0);
double top = topPadding;
if (hasInlineLabel)
top += topPaddingIncrement + baseStyle.fontSize - labelStyle.fontSize;
final double topPaddingIncrement = labelTextHeight + (isDense ? _kDensePadding : _kNormalPadding);
stackChildren.add( stackChildren.add(
new AnimatedPositionedDirectional( new AnimatedPositionedDirectional(
start: 0.0, start: 0.0,
top: topPadding + (hasInlineLabel ? topPaddingIncrement : 0.0), top: top,
duration: _kTransitionDuration, duration: _kTransitionDuration,
curve: _kTransitionCurve, curve: _kTransitionCurve,
child: new _AnimatedLabel( child: new _AnimatedLabel(
...@@ -484,12 +483,10 @@ class InputDecorator extends StatelessWidget { ...@@ -484,12 +483,10 @@ class InputDecorator extends StatelessWidget {
if (hintText != null) { if (hintText != null) {
stackChildren.add( stackChildren.add(
new AnimatedPositionedDirectional( new Positioned(
start: 0.0, left: 0.0,
end: 0.0, right: 0.0,
top: topPadding, top: topPadding + baseStyle.fontSize - hintStyle.fontSize,
duration: _kTransitionDuration,
curve: _kTransitionCurve,
child: new AnimatedOpacity( child: new AnimatedOpacity(
opacity: (isEmpty && !hasInlineLabel) ? 1.0 : 0.0, opacity: (isEmpty && !hasInlineLabel) ? 1.0 : 0.0,
duration: _kTransitionDuration, duration: _kTransitionDuration,
...@@ -537,43 +534,33 @@ class InputDecorator extends StatelessWidget { ...@@ -537,43 +534,33 @@ class InputDecorator extends StatelessWidget {
inputChild = new Row(children: rowContents); inputChild = new Row(children: rowContents);
} }
// The inputChild and the helper/error text need to be in a column so that if the inputChild is
// a multiline input or a non-text widget, it lays out with the helper/error text below the
// inputChild.
final List<Widget> columnChildren = <Widget>[];
if (isCollapsed) { if (isCollapsed) {
columnChildren.add(inputChild); stackChildren.add(inputChild);
} else { } else {
final Color borderColor = errorText == null ? activeColor : themeData.errorColor; final Color borderColor = errorText == null ? activeColor : themeData.errorColor;
columnChildren.add(_buildContent(borderColor, topPadding, isDense, inputChild, subTextHeight)); stackChildren.add(_buildContent(borderColor, topPadding, isDense, inputChild));
} }
if (errorText != null || helperText != null) { if (!isDense && (errorText != null || helperText != null)) {
assert(!isCollapsed); assert(!isCollapsed);
final double linePadding = _kBottomBorderHeight + (isDense ? _kDensePadding : _kNormalPadding); final TextStyle captionStyle = themeData.textTheme.caption;
columnChildren.add( final TextStyle subtextStyle = errorText != null
new AnimatedContainer( ? decoration.errorStyle ?? captionStyle.copyWith(color: themeData.errorColor)
padding: new EdgeInsets.only(top: linePadding), : decoration.helperStyle ?? captionStyle.copyWith(color: themeData.hintColor);
duration: _kTransitionDuration,
curve: _kTransitionCurve, stackChildren.add(new Positioned(
left: 0.0,
right: 0.0,
bottom: 0.0,
child: new Text( child: new Text(
errorText ?? helperText, errorText ?? helperText,
style: subtextStyle, style: subtextStyle,
textAlign: textAlign, textAlign: textAlign,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ));
);
} }
stackChildren.add(
new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: columnChildren,
),
);
final Widget stack = new Stack( final Widget stack = new Stack(
fit: StackFit.passthrough, fit: StackFit.passthrough,
children: stackChildren children: stackChildren
...@@ -582,19 +569,17 @@ class InputDecorator extends StatelessWidget { ...@@ -582,19 +569,17 @@ class InputDecorator extends StatelessWidget {
if (decoration.icon != null) { if (decoration.icon != null) {
assert(!isCollapsed); assert(!isCollapsed);
final double iconSize = isDense ? 18.0 : 24.0; final double iconSize = isDense ? 18.0 : 24.0;
final double iconTop = topPadding + (entryTextHeight - iconSize) / 2.0; final double iconTop = topPadding + (baseStyle.fontSize - iconSize) / 2.0;
return new Row( return new Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new AnimatedContainer( new Container(
margin: new EdgeInsets.only(top: iconTop), margin: new EdgeInsets.only(top: iconTop),
duration: _kTransitionDuration,
curve: _kTransitionCurve,
width: isDense ? 40.0 : 48.0, width: isDense ? 40.0 : 48.0,
child: IconTheme.merge( child: IconTheme.merge(
data: new IconThemeData( data: new IconThemeData(
color: isFocused ? activeColor : Colors.black45, color: isFocused ? activeColor : Colors.black45,
size: iconSize, size: isDense ? 18.0 : 24.0,
), ),
child: decoration.icon, child: decoration.icon,
), ),
...@@ -620,15 +605,11 @@ class _AnimatedLabel extends ImplicitlyAnimatedWidget { ...@@ -620,15 +605,11 @@ class _AnimatedLabel extends ImplicitlyAnimatedWidget {
@required this.style, @required this.style,
Curve curve: Curves.linear, Curve curve: Curves.linear,
@required Duration duration, @required Duration duration,
this.textAlign,
this.overflow,
}) : assert(style != null), }) : assert(style != null),
super(key: key, curve: curve, duration: duration); super(key: key, curve: curve, duration: duration);
final String text; final String text;
final TextStyle style; final TextStyle style;
final TextAlign textAlign;
final TextOverflow overflow;
@override @override
_AnimatedLabelState createState() => new _AnimatedLabelState(); _AnimatedLabelState createState() => new _AnimatedLabelState();
...@@ -665,8 +646,6 @@ class _AnimatedLabelState extends AnimatedWidgetBaseState<_AnimatedLabel> { ...@@ -665,8 +646,6 @@ class _AnimatedLabelState extends AnimatedWidgetBaseState<_AnimatedLabel> {
child: new Text( child: new Text(
widget.text, widget.text,
style: style, style: style,
textAlign: widget.textAlign,
overflow: widget.overflow,
), ),
); );
} }
......
...@@ -134,7 +134,6 @@ class TextPainter { ...@@ -134,7 +134,6 @@ class TextPainter {
return; return;
_textScaleFactor = value; _textScaleFactor = value;
_paragraph = null; _paragraph = null;
_layoutTemplate = null;
_needsLayout = true; _needsLayout = true;
} }
......
...@@ -1964,7 +1964,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im ...@@ -1964,7 +1964,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
// yet (that is, our layer might not have been detached yet), because the // yet (that is, our layer might not have been detached yet), because the
// same node that skipped us in layout is above us in the tree (obviously) // same node that skipped us in layout is above us in the tree (obviously)
// and therefore may not have had a chance to paint yet (since the tree // and therefore may not have had a chance to paint yet (since the tree
// paints in reverse order). In particular this will happen if they have // paints in reverse order). In particular this will happen if they are have
// a different layer, because there's a repaint boundary between us. // a different layer, because there's a repaint boundary between us.
if (_needsLayout) if (_needsLayout)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment