Unverified Commit 6758b55c authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix weird bug when switching text from errorText to helperText (#15390)

parent 0e8b1877
...@@ -277,16 +277,19 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta ...@@ -277,16 +277,19 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
void didUpdateWidget(_HelperError old) { void didUpdateWidget(_HelperError old) {
super.didUpdateWidget(old); super.didUpdateWidget(old);
final String errorText = widget.errorText; final String newErrorText = widget.errorText;
final String helperText = widget.helperText; final String newHelperText = widget.helperText;
final String oldErrorText = old.errorText; final String oldErrorText = old.errorText;
final String oldHelperText = old.helperText; final String oldHelperText = old.helperText;
if ((errorText ?? helperText) != (oldErrorText ?? oldHelperText)) { final bool errorTextStateChanged = (newErrorText != null) != (oldErrorText != null);
if (errorText != null) { final bool helperTextStateChanged = newErrorText == null && (newHelperText != null) != (oldHelperText != null);
if (errorTextStateChanged || helperTextStateChanged) {
if (newErrorText != null) {
_error = _buildError(); _error = _buildError();
_controller.forward(); _controller.forward();
} else if (helperText != null) { } else if (newHelperText != null) {
_helper = _buildHelper(); _helper = _buildHelper();
_controller.reverse(); _controller.reverse();
} else { } else {
...@@ -1818,6 +1821,9 @@ class InputDecoration { ...@@ -1818,6 +1821,9 @@ class InputDecoration {
/// ///
/// If non-null, the border's color animates to red and the [helperText] is /// If non-null, the border's color animates to red and the [helperText] is
/// not shown. /// not shown.
///
/// In a [TextFormField], this is overridden by the value returned from
/// [TextFormField.validator], if that is not null.
final String errorText; final String errorText;
/// The style to use for the [errorText]. /// The style to use for the [errorText].
......
...@@ -337,6 +337,8 @@ class SliderThemeData extends Diagnosticable { ...@@ -337,6 +337,8 @@ class SliderThemeData extends Diagnosticable {
/// when the thumb is being touched. /// when the thumb is being touched.
final ShowValueIndicator showValueIndicator; final ShowValueIndicator showValueIndicator;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
SliderThemeData copyWith({ SliderThemeData copyWith({
Color activeRailColor, Color activeRailColor,
Color inactiveRailColor, Color inactiveRailColor,
...@@ -537,7 +539,9 @@ abstract class SliderComponentShape { ...@@ -537,7 +539,9 @@ abstract class SliderComponentShape {
/// * [SliderThemeData] where an instance of this class is set to inform the /// * [SliderThemeData] where an instance of this class is set to inform the
/// slider of the shape of the its thumb. /// slider of the shape of the its thumb.
class RoundSliderThumbShape extends SliderComponentShape { class RoundSliderThumbShape extends SliderComponentShape {
/// Create a slider thumb that draws a circle.
const RoundSliderThumbShape(); const RoundSliderThumbShape();
static const double _thumbRadius = 6.0; static const double _thumbRadius = 6.0;
static const double _disabledThumbRadius = 4.0; static const double _disabledThumbRadius = 4.0;
...@@ -585,6 +589,7 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -585,6 +589,7 @@ class RoundSliderThumbShape extends SliderComponentShape {
/// * [SliderThemeData] where an instance of this class is set to inform the /// * [SliderThemeData] where an instance of this class is set to inform the
/// slider of the shape of the its value indicator. /// slider of the shape of the its value indicator.
class PaddleSliderValueIndicatorShape extends SliderComponentShape { class PaddleSliderValueIndicatorShape extends SliderComponentShape {
/// Create a slider value indicator in the shape of an upside-down pear.
const PaddleSliderValueIndicatorShape(); const PaddleSliderValueIndicatorShape();
// These constants define the shape of the default value indicator. // These constants define the shape of the default value indicator.
......
...@@ -213,6 +213,8 @@ class TextField extends StatefulWidget { ...@@ -213,6 +213,8 @@ class TextField extends StatefulWidget {
/// characters may be entered, but the error counter and divider will /// characters may be entered, but the error counter and divider will
/// switch to the [decoration.errorStyle] when the limit is exceeded. /// switch to the [decoration.errorStyle] when the limit is exceeded.
/// ///
/// ## Limitations
///
/// The TextField does not currently count Unicode grapheme clusters (i.e. /// The TextField does not currently count Unicode grapheme clusters (i.e.
/// characters visible to the user), it counts Unicode scalar values, which /// characters visible to the user), it counts Unicode scalar values, which
/// leaves out a number of useful possible characters (like many emoji and /// leaves out a number of useful possible characters (like many emoji and
......
...@@ -218,6 +218,10 @@ class FormField<T> extends StatefulWidget { ...@@ -218,6 +218,10 @@ class FormField<T> extends StatefulWidget {
/// An optional method that validates an input. Returns an error string to /// An optional method that validates an input. Returns an error string to
/// display if the input is invalid, or null otherwise. /// display if the input is invalid, or null otherwise.
///
/// The returned value is exposed by the [FormFieldState.errorText] property.
/// The [TextFormField] uses this to override the [InputDecoration.errorText]
/// value.
final FormFieldValidator<T> validator; final FormFieldValidator<T> validator;
/// Function that returns the widget representing this form field. It is /// Function that returns the widget representing this form field. It is
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('TextField works correctly when changing helperText', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp(home: const TextField(decoration: const InputDecoration(helperText: 'Awesome'))));
expect(find.text('Awesome'), findsNWidgets(1));
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Awesome'), findsNWidgets(1));
await tester.pumpWidget(new MaterialApp(home: const TextField(decoration: const InputDecoration(errorText: 'Awesome'))));
expect(find.text('Awesome'), findsNWidgets(2));
});
}
\ No newline at end of file
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