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
void didUpdateWidget(_HelperError old) {
super.didUpdateWidget(old);
final String errorText = widget.errorText;
final String helperText = widget.helperText;
final String newErrorText = widget.errorText;
final String newHelperText = widget.helperText;
final String oldErrorText = old.errorText;
final String oldHelperText = old.helperText;
if ((errorText ?? helperText) != (oldErrorText ?? oldHelperText)) {
if (errorText != null) {
final bool errorTextStateChanged = (newErrorText != null) != (oldErrorText != null);
final bool helperTextStateChanged = newErrorText == null && (newHelperText != null) != (oldHelperText != null);
if (errorTextStateChanged || helperTextStateChanged) {
if (newErrorText != null) {
_error = _buildError();
_controller.forward();
} else if (helperText != null) {
} else if (newHelperText != null) {
_helper = _buildHelper();
_controller.reverse();
} else {
......@@ -1818,6 +1821,9 @@ class InputDecoration {
///
/// If non-null, the border's color animates to red and the [helperText] is
/// not shown.
///
/// In a [TextFormField], this is overridden by the value returned from
/// [TextFormField.validator], if that is not null.
final String errorText;
/// The style to use for the [errorText].
......
......@@ -337,6 +337,8 @@ class SliderThemeData extends Diagnosticable {
/// when the thumb is being touched.
final ShowValueIndicator showValueIndicator;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
SliderThemeData copyWith({
Color activeRailColor,
Color inactiveRailColor,
......@@ -537,7 +539,9 @@ abstract class SliderComponentShape {
/// * [SliderThemeData] where an instance of this class is set to inform the
/// slider of the shape of the its thumb.
class RoundSliderThumbShape extends SliderComponentShape {
/// Create a slider thumb that draws a circle.
const RoundSliderThumbShape();
static const double _thumbRadius = 6.0;
static const double _disabledThumbRadius = 4.0;
......@@ -585,6 +589,7 @@ class RoundSliderThumbShape extends SliderComponentShape {
/// * [SliderThemeData] where an instance of this class is set to inform the
/// slider of the shape of the its value indicator.
class PaddleSliderValueIndicatorShape extends SliderComponentShape {
/// Create a slider value indicator in the shape of an upside-down pear.
const PaddleSliderValueIndicatorShape();
// These constants define the shape of the default value indicator.
......
......@@ -213,6 +213,8 @@ class TextField extends StatefulWidget {
/// characters may be entered, but the error counter and divider will
/// switch to the [decoration.errorStyle] when the limit is exceeded.
///
/// ## Limitations
///
/// The TextField does not currently count Unicode grapheme clusters (i.e.
/// characters visible to the user), it counts Unicode scalar values, which
/// leaves out a number of useful possible characters (like many emoji and
......
......@@ -218,6 +218,10 @@ class FormField<T> extends StatefulWidget {
/// An optional method that validates an input. Returns an error string to
/// 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;
/// 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