Update InputDecorator et al (#13734)
This commit is contained in:
@@ -55,6 +55,7 @@ export 'src/material/icons.dart';
|
||||
export 'src/material/ink_highlight.dart';
|
||||
export 'src/material/ink_splash.dart';
|
||||
export 'src/material/ink_well.dart';
|
||||
export 'src/material/input_border.dart';
|
||||
export 'src/material/input_decorator.dart';
|
||||
export 'src/material/list_tile.dart';
|
||||
export 'src/material/material.dart';
|
||||
|
||||
413
packages/flutter/lib/src/material/input_border.dart
Normal file
413
packages/flutter/lib/src/material/input_border.dart
Normal file
@@ -0,0 +1,413 @@
|
||||
// Copyright 2017 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 'dart:math' as math;
|
||||
import 'dart:ui' show lerpDouble;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Defines the appearance of an [InputDecorator]'s border.
|
||||
///
|
||||
/// An input decorator's border is specified by [InputDecoration.border].
|
||||
///
|
||||
/// The border is drawn relative to the input decorator's "container" which
|
||||
/// is the optionally filled area above the decorator's helper, error,
|
||||
/// and counter.
|
||||
///
|
||||
/// Input border's are decorated with a line whose weight and color are defined
|
||||
/// by [borderSide]. The input decorator's renderer animates the input border's
|
||||
/// appearance in response to state changes, like gaining or losing the focus,
|
||||
/// by creating new copies of its input border with [copyWith].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [UnderlineInputBorder], the default [InputDecorator] border which
|
||||
/// draws a horizontal line at the bottom of the input decorator's container.
|
||||
/// * [OutlineInputBorder], an [InputDecorator] border which draws a
|
||||
/// rounded rectangle around the input decorator's container.
|
||||
/// * [InputDecoration], which is used to configure an [InputDecorator].
|
||||
abstract class InputBorder extends ShapeBorder {
|
||||
/// Creates a border for an [InputDecorator].
|
||||
///
|
||||
/// The [borderSide] parameter must not be null. Applications typically do
|
||||
/// not specify a [borderSide] parameter because the input decorator
|
||||
/// substitutes its own, using [copyWith], based on the current theme and
|
||||
/// [InputDecorator.isFocused].
|
||||
const InputBorder({
|
||||
this.borderSide: BorderSide.none,
|
||||
}) : assert(borderSide != null);
|
||||
|
||||
/// Defines the border line's color and weight.
|
||||
///
|
||||
/// The [InputDecorator] creates copies of its input border, using [copyWith],
|
||||
/// based on the current theme and [InputDecorator.isFocused].
|
||||
final BorderSide borderSide;
|
||||
|
||||
/// Creates a copy of this input border with the specified `borderSide`.
|
||||
InputBorder copyWith({ BorderSide borderSide });
|
||||
|
||||
/// True if this border will enclose the [InputDecorator]'s container.
|
||||
///
|
||||
/// This property affects the alignment of container's contents. For example
|
||||
/// when an input decorator is configured with an [OutlineInputBorder] its
|
||||
/// label is centered with its container.
|
||||
bool get isOutline;
|
||||
|
||||
/// Paint this input border on [canvas].
|
||||
///
|
||||
/// The [rect] parameter bounds the [InputDecorator]'s container.
|
||||
///
|
||||
/// The additional `gap` parameters reflect the state of the [InputDecorator]'s
|
||||
/// floating label. When an input decorator gains the focus, its label
|
||||
/// animates upwards, to make room for the input child. The [gapStart] and
|
||||
/// [gapExtent] parameters define a floating label width interval, and
|
||||
/// [gapPercentage] defines the animation's progress (0.0 to 1.0).
|
||||
@override
|
||||
void paint(Canvas canvas, Rect rect, {
|
||||
double gapStart,
|
||||
double gapExtent: 0.0,
|
||||
double gapPercentage: 0.0,
|
||||
TextDirection textDirection,
|
||||
});
|
||||
}
|
||||
|
||||
/// Draws a horizontal line at the bottom of an [InputDecorator]'s container.
|
||||
///
|
||||
/// The input decorator's "container" is the optionally filled area above the
|
||||
/// decorator's helper, error, and counter.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [OutlineInputBorder], an [InputDecorator] border which draws a
|
||||
/// rounded rectangle around the input decorator's container.
|
||||
/// * [InputDecoration], which is used to configure an [InputDecorator].
|
||||
class UnderlineInputBorder extends InputBorder {
|
||||
/// Creates an underline border for an [InputDecorator].
|
||||
///
|
||||
/// The [borderSide] parameter defaults to [BorderSide.none] (it must not be
|
||||
/// null). Applications typically do not specify a [borderSide] parameter
|
||||
/// because the input decorator substitutes its own, using [copyWith], based
|
||||
/// on the current theme and [InputDecorator.isFocused].
|
||||
const UnderlineInputBorder({
|
||||
BorderSide borderSide: BorderSide.none,
|
||||
}) : super(borderSide: borderSide);
|
||||
|
||||
@override
|
||||
bool get isOutline => false;
|
||||
|
||||
@override
|
||||
UnderlineInputBorder copyWith({ BorderSide borderSide }) {
|
||||
return new UnderlineInputBorder(borderSide: borderSide ?? this.borderSide);
|
||||
}
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry get dimensions {
|
||||
return new EdgeInsets.only(bottom: borderSide.width);
|
||||
}
|
||||
|
||||
@override
|
||||
UnderlineInputBorder scale(double t) {
|
||||
return new UnderlineInputBorder(borderSide: borderSide.scale(t));
|
||||
}
|
||||
|
||||
@override
|
||||
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
|
||||
return new Path()
|
||||
..addRect(new Rect.fromLTWH(rect.left, rect.top, rect.width, math.max(0.0, rect.height - borderSide.width)));
|
||||
}
|
||||
|
||||
@override
|
||||
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
|
||||
return new Path()..addRect(rect);
|
||||
}
|
||||
|
||||
@override
|
||||
ShapeBorder lerpFrom(ShapeBorder a, double t) {
|
||||
if (a is UnderlineInputBorder) {
|
||||
return new UnderlineInputBorder(
|
||||
borderSide: BorderSide.lerp(a.borderSide, borderSide, t),
|
||||
);
|
||||
}
|
||||
return super.lerpFrom(a, t);
|
||||
}
|
||||
|
||||
@override
|
||||
ShapeBorder lerpTo(ShapeBorder b, double t) {
|
||||
if (b is UnderlineInputBorder) {
|
||||
return new UnderlineInputBorder(
|
||||
borderSide: BorderSide.lerp(borderSide, b.borderSide, t),
|
||||
);
|
||||
}
|
||||
return super.lerpTo(b, t);
|
||||
}
|
||||
|
||||
/// Draw a horizontal line at the bottom of [rect].
|
||||
///
|
||||
/// The [borderSide] defines the line's color and weight. The `textDirection`
|
||||
/// `gap` and `textDirection` parameters are ignored.
|
||||
@override
|
||||
void paint(Canvas canvas, Rect rect, {
|
||||
double gapStart,
|
||||
double gapExtent: 0.0,
|
||||
double gapPercentage: 0.0,
|
||||
TextDirection textDirection,
|
||||
}) {
|
||||
canvas.drawLine(rect.bottomLeft, rect.bottomRight, borderSide.toPaint());
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (runtimeType != other.runtimeType)
|
||||
return false;
|
||||
final InputBorder typedOther = other;
|
||||
return typedOther.borderSide == borderSide;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => borderSide.hashCode;
|
||||
}
|
||||
|
||||
/// Draws a rounded rectangle around an [InputDecorator]'s container.
|
||||
///
|
||||
/// When the input decorator's label is floating, for example because its
|
||||
/// input child has the focus, the label appears in a gap in the border outline.
|
||||
///
|
||||
/// The input decorator's "container" is the optionally filled area above the
|
||||
/// decorator's helper, error, and counter.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [UnderlineInputBorder], the default [InputDecorator] border which
|
||||
/// draws a horizontal line at the bottom of the input decorator's container.
|
||||
/// * [InputDecoration], which is used to configure an [InputDecorator].
|
||||
class OutlineInputBorder extends InputBorder {
|
||||
/// Creates a rounded rectangle outline border for an [InputDecorator].
|
||||
///
|
||||
/// The [borderSide] parameter defaults to [BorderSide.none] (it must not be
|
||||
/// null). Applications typically do not specify a [borderSide] parameter
|
||||
/// because the input decorator substitutes its own, using [copyWith], based
|
||||
/// on the current theme and [InputDecorator.isFocused].
|
||||
///
|
||||
/// If [borderRadius] is null (the default) then the border's corners
|
||||
/// are drawn with a radius of 4 logical pixels. The corner radii must be
|
||||
/// circular, i.e. their [Radius.x] and [Radius.y] values must be the same.
|
||||
const OutlineInputBorder({
|
||||
BorderSide borderSide: BorderSide.none,
|
||||
this.borderRadius: const BorderRadius.all(const Radius.circular(4.0)),
|
||||
this.gapPadding: 4.0,
|
||||
}) : assert(borderRadius != null),
|
||||
assert(gapPadding != null && gapPadding >= 0.0),
|
||||
super(borderSide: borderSide);
|
||||
|
||||
// The label text's gap can extend into the corners (even both the top left
|
||||
// and the top right corner). To avoid the more complicated problem of finding
|
||||
// how far the gap penetrates into an elliptical corner, just require them
|
||||
// to be circular.
|
||||
//
|
||||
// This can't be checked by the constructor because const constructor.
|
||||
static bool _cornersAreCircular(BorderRadius borderRadius) {
|
||||
return borderRadius.topLeft.x == borderRadius.topLeft.y
|
||||
&& borderRadius.bottomLeft.x == borderRadius.bottomLeft.y
|
||||
&& borderRadius.topRight.x == borderRadius.topRight.y
|
||||
&& borderRadius.bottomRight.x == borderRadius.bottomRight.y;
|
||||
}
|
||||
|
||||
/// Horizontal padding on either side of the border's
|
||||
/// [InputDecoration.labelText] width gap.
|
||||
///
|
||||
/// This value is used by the [paint] method to compute the actual gap width.
|
||||
final double gapPadding;
|
||||
|
||||
/// The radii of the border's rounded rectangle corners.
|
||||
///
|
||||
/// The corner radii must be circular, i.e. their [Radius.x] and [Radius.y]
|
||||
/// values must be the same.
|
||||
final BorderRadius borderRadius;
|
||||
|
||||
@override
|
||||
bool get isOutline => true;
|
||||
|
||||
@override
|
||||
OutlineInputBorder copyWith({
|
||||
BorderSide borderSide,
|
||||
BorderRadius borderRadius,
|
||||
double gapPadding,
|
||||
}) {
|
||||
return new OutlineInputBorder(
|
||||
borderSide: borderSide ?? this.borderSide,
|
||||
borderRadius: borderRadius ?? this.borderRadius,
|
||||
gapPadding: gapPadding ?? this.gapPadding,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry get dimensions {
|
||||
return new EdgeInsets.all(borderSide.width);
|
||||
}
|
||||
|
||||
@override
|
||||
OutlineInputBorder scale(double t) {
|
||||
return new OutlineInputBorder(
|
||||
borderSide: borderSide.scale(t),
|
||||
borderRadius: borderRadius * t,
|
||||
gapPadding: gapPadding * t,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ShapeBorder lerpFrom(ShapeBorder a, double t) {
|
||||
if (a is OutlineInputBorder) {
|
||||
final OutlineInputBorder outline = a;
|
||||
return new OutlineInputBorder(
|
||||
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t),
|
||||
borderSide: BorderSide.lerp(outline.borderSide, borderSide, t),
|
||||
gapPadding: outline.gapPadding,
|
||||
);
|
||||
}
|
||||
return super.lerpFrom(a, t);
|
||||
}
|
||||
|
||||
@override
|
||||
ShapeBorder lerpTo(ShapeBorder b, double t) {
|
||||
if (b is OutlineInputBorder) {
|
||||
final OutlineInputBorder outline = b;
|
||||
return new OutlineInputBorder(
|
||||
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t),
|
||||
borderSide: BorderSide.lerp(borderSide, outline.borderSide, t),
|
||||
gapPadding: outline.gapPadding,
|
||||
);
|
||||
}
|
||||
return super.lerpTo(b, t);
|
||||
}
|
||||
|
||||
@override
|
||||
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
|
||||
return new Path()
|
||||
..addRRect(borderRadius.resolve(textDirection).toRRect(rect).deflate(borderSide.width));
|
||||
}
|
||||
|
||||
@override
|
||||
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
|
||||
return new Path()
|
||||
..addRRect(borderRadius.resolve(textDirection).toRRect(rect));
|
||||
}
|
||||
|
||||
Path _gapBorderPath(Canvas canvas, RRect center, double start, double extent) {
|
||||
final Rect tlCorner = new Rect.fromLTWH(
|
||||
center.left,
|
||||
center.top,
|
||||
center.tlRadiusX * 2.0,
|
||||
center.tlRadiusY * 2.0,
|
||||
);
|
||||
final Rect trCorner = new Rect.fromLTWH(
|
||||
center.right - center.trRadiusX * 2.0,
|
||||
center.top,
|
||||
center.trRadiusX * 2.0,
|
||||
center.trRadiusY * 2.0,
|
||||
);
|
||||
final Rect brCorner = new Rect.fromLTWH(
|
||||
center.right - center.brRadiusX * 2.0,
|
||||
center.bottom - center.brRadiusY * 2.0,
|
||||
center.brRadiusX * 2.0,
|
||||
center.brRadiusY * 2.0,
|
||||
);
|
||||
final Rect blCorner = new Rect.fromLTWH(
|
||||
center.left,
|
||||
center.bottom - center.brRadiusY * 2.0,
|
||||
center.blRadiusX * 2.0,
|
||||
center.blRadiusY * 2.0,
|
||||
);
|
||||
|
||||
final double cornerArcSweep = math.PI / 2.0;
|
||||
final double tlCornerArcSweep = start < center.tlRadiusX
|
||||
? math.asin(start / center.tlRadiusX)
|
||||
: math.PI / 2.0;
|
||||
|
||||
final Path path = new Path()
|
||||
..addArc(tlCorner, math.PI, tlCornerArcSweep)
|
||||
..moveTo(center.left + center.tlRadiusX, center.top);
|
||||
|
||||
if (start > center.tlRadiusX)
|
||||
path.lineTo(center.left + start, center.top);
|
||||
|
||||
final double trCornerArcStart = (3 * math.PI) / 2.0;
|
||||
final double trCornerArcSweep = cornerArcSweep;
|
||||
if (start + extent < center.width - center.trRadiusX) {
|
||||
path
|
||||
..relativeMoveTo(extent, 0.0)
|
||||
..lineTo(center.right - center.trRadiusX, center.top)
|
||||
..addArc(trCorner, trCornerArcStart, trCornerArcSweep);
|
||||
} else if (start + extent < center.width) {
|
||||
final double dx = center.width - (start + extent);
|
||||
final double sweep = math.acos(dx / center.trRadiusX);
|
||||
path.addArc(trCorner, trCornerArcStart + sweep, trCornerArcSweep - sweep);
|
||||
}
|
||||
|
||||
return path
|
||||
..moveTo(center.right, center.top + center.trRadiusY)
|
||||
..lineTo(center.right, center.bottom - center.brRadiusY)
|
||||
..addArc(brCorner, 0.0, cornerArcSweep)
|
||||
..lineTo(center.left + center.blRadiusX, center.bottom)
|
||||
..addArc(blCorner, math.PI / 2.0, cornerArcSweep)
|
||||
..lineTo(center.left, center.top + center.trRadiusY);
|
||||
}
|
||||
|
||||
/// Draw a rounded rectangle around [rect] using [borderRadius].
|
||||
///
|
||||
/// The [borderSide] defines the line's color and weight.
|
||||
///
|
||||
/// The top side of the rounded rectangle may be interrupted by a single gap
|
||||
/// if [gapExtent] is non-null. In that case the gap begins at
|
||||
/// `gapStart - gapPadding` (assuming that the [textDirection] is [TextDirection.ltr]).
|
||||
/// The gap's width is `(gapPadding + gapExtent + gapPadding) * gapPercentage`.
|
||||
@override
|
||||
void paint(Canvas canvas, Rect rect, {
|
||||
double gapStart,
|
||||
double gapExtent: 0.0,
|
||||
double gapPercentage: 0.0,
|
||||
TextDirection textDirection,
|
||||
}) {
|
||||
assert(gapExtent != null);
|
||||
assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);
|
||||
assert(_cornersAreCircular(borderRadius));
|
||||
|
||||
final Paint paint = borderSide.toPaint();
|
||||
final RRect outer = borderRadius.toRRect(rect);
|
||||
final RRect center = outer.deflate(borderSide.width / 2.0);
|
||||
if (gapStart == null || gapExtent <= 0.0 || gapPercentage == 0.0) {
|
||||
canvas.drawRRect(center, paint);
|
||||
} else {
|
||||
final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
|
||||
switch (textDirection) {
|
||||
case TextDirection.rtl: {
|
||||
final Path path = _gapBorderPath(canvas, center, gapStart + gapPadding - extent, extent);
|
||||
canvas.drawPath(path, paint);
|
||||
break;
|
||||
}
|
||||
case TextDirection.ltr: {
|
||||
final Path path = _gapBorderPath(canvas, center, gapStart - gapPadding, extent);
|
||||
canvas.drawPath(path, paint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (runtimeType != other.runtimeType)
|
||||
return false;
|
||||
final OutlineInputBorder typedOther = other;
|
||||
return typedOther.borderSide == borderSide
|
||||
&& typedOther.borderRadius == borderRadius
|
||||
&& typedOther.gapPadding == gapPadding;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hashValues(borderSide, borderRadius, gapPadding);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'feedback.dart';
|
||||
import 'input_decorator.dart';
|
||||
import 'material.dart';
|
||||
import 'text_selection.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ class _ShapeDecorationPainter extends BoxPainter {
|
||||
final ShapeDecoration _decoration;
|
||||
|
||||
Rect _lastRect;
|
||||
TextDirection _lastTextDirection;
|
||||
Path _outerPath;
|
||||
Path _innerPath;
|
||||
Paint _interiorPaint;
|
||||
@@ -292,10 +293,11 @@ class _ShapeDecorationPainter extends BoxPainter {
|
||||
List<Path> _shadowPaths;
|
||||
List<Paint> _shadowPaints;
|
||||
|
||||
void _precache(Rect rect) {
|
||||
void _precache(Rect rect, TextDirection textDirection) {
|
||||
assert(rect != null);
|
||||
if (rect == _lastRect)
|
||||
if (rect == _lastRect && textDirection == _lastTextDirection)
|
||||
return;
|
||||
|
||||
// We reach here in two cases:
|
||||
// - the very first time we paint, in which case everything except _decoration is null
|
||||
// - subsequent times, if the rect has changed, in which case we only need to update
|
||||
@@ -328,7 +330,9 @@ class _ShapeDecorationPainter extends BoxPainter {
|
||||
_outerPath = _decoration.shape.getOuterPath(rect);
|
||||
if (_decoration.image != null)
|
||||
_innerPath = _decoration.shape.getInnerPath(rect);
|
||||
|
||||
_lastRect = rect;
|
||||
_lastTextDirection = textDirection;
|
||||
}
|
||||
|
||||
void _paintShadows(Canvas canvas) {
|
||||
@@ -362,10 +366,11 @@ class _ShapeDecorationPainter extends BoxPainter {
|
||||
assert(configuration != null);
|
||||
assert(configuration.size != null);
|
||||
final Rect rect = offset & configuration.size;
|
||||
_precache(rect);
|
||||
final TextDirection textDirection = configuration.textDirection;
|
||||
_precache(rect, textDirection);
|
||||
_paintShadows(canvas);
|
||||
_paintInterior(canvas);
|
||||
_paintImage(canvas, configuration);
|
||||
_decoration.shape.paint(canvas, rect);
|
||||
_decoration.shape.paint(canvas, rect, textDirection: textDirection);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -104,6 +104,15 @@ Future<Null> skipPastScrollingAnimation(WidgetTester tester) async {
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
}
|
||||
|
||||
double getOpacity(WidgetTester tester, Finder finder) {
|
||||
return tester.widget<Opacity>(
|
||||
find.ancestor(
|
||||
of: finder,
|
||||
matching: find.byType(Opacity),
|
||||
)
|
||||
).opacity;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final MockClipboard mockClipboard = new MockClipboard();
|
||||
SystemChannels.platform.setMockMethodCallHandler(mockClipboard.handleMethodCall);
|
||||
@@ -1006,33 +1015,26 @@ void main() {
|
||||
);
|
||||
|
||||
// Neither the prefix or the suffix should initially be visible, only the hint.
|
||||
expect(find.text('Prefix'), findsNothing);
|
||||
expect(find.text('Suffix'), findsNothing);
|
||||
expect(find.text('Hint'), findsOneWidget);
|
||||
expect(getOpacity(tester, find.text('Prefix')), 0.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 0.0);
|
||||
expect(getOpacity(tester, find.text('Hint')), 1.0);
|
||||
|
||||
await tester.tap(find.byKey(secondKey));
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Focus the Input. The hint should display, but not the prefix and suffix.
|
||||
expect(find.text('Prefix'), findsNothing);
|
||||
expect(find.text('Suffix'), findsNothing);
|
||||
expect(find.text('Hint'), findsOneWidget);
|
||||
// Focus the Input. The hint, prefix, and suffix should appear
|
||||
expect(getOpacity(tester, find.text('Prefix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Hint')), 1.0);
|
||||
|
||||
// Enter some text, and the hint should disappear and the prefix and suffix
|
||||
// should appear.
|
||||
// should continue to be visible
|
||||
await tester.enterText(find.byKey(secondKey), 'Hi');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Prefix'), findsOneWidget);
|
||||
expect(find.text('Suffix'), findsOneWidget);
|
||||
|
||||
// It's onstage, but animated to zero opacity.
|
||||
expect(find.text('Hint'), findsOneWidget);
|
||||
final Element target = tester.element(find.text('Hint'));
|
||||
final Opacity opacity = target.ancestorWidgetOfExactType(Opacity);
|
||||
expect(opacity, isNotNull);
|
||||
expect(opacity.opacity, equals(0.0));
|
||||
expect(getOpacity(tester, find.text('Prefix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Hint')), 0.0);
|
||||
|
||||
// Check and make sure that the right styles were applied.
|
||||
final Text prefixText = tester.widget(find.text('Prefix'));
|
||||
@@ -1077,27 +1079,25 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
// Not focused. The prefix should not display, but the label should.
|
||||
expect(find.text('Prefix'), findsNothing);
|
||||
expect(find.text('Suffix'), findsNothing);
|
||||
// Not focused. The prefix and suffix should not appear, but the label should.
|
||||
expect(getOpacity(tester, find.text('Prefix')), 0.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 0.0);
|
||||
expect(find.text('Label'), findsOneWidget);
|
||||
|
||||
// Focus the input. The label, prefix, and suffix should appear.
|
||||
await tester.tap(find.byKey(secondKey));
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Focus the input. The label should display, and also the prefix.
|
||||
expect(find.text('Prefix'), findsOneWidget);
|
||||
expect(find.text('Suffix'), findsOneWidget);
|
||||
expect(getOpacity(tester, find.text('Prefix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 1.0);
|
||||
expect(find.text('Label'), findsOneWidget);
|
||||
|
||||
// Enter some text, and the label should stay and the prefix should
|
||||
// remain.
|
||||
// Enter some text. The label, prefix, and suffix should remain visible.
|
||||
await tester.enterText(find.byKey(secondKey), 'Hi');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Prefix'), findsOneWidget);
|
||||
expect(find.text('Suffix'), findsOneWidget);
|
||||
expect(getOpacity(tester, find.text('Prefix')), 1.0);
|
||||
expect(getOpacity(tester, find.text('Suffix')), 1.0);
|
||||
expect(find.text('Label'), findsOneWidget);
|
||||
|
||||
// Check and make sure that the right styles were applied.
|
||||
@@ -1148,21 +1148,25 @@ void main() {
|
||||
expect(newPos.dy, lessThan(pos.dy));
|
||||
});
|
||||
|
||||
testWidgets('No space between Input icon and text', (WidgetTester tester) async {
|
||||
testWidgets('Icon is separated from input/label by 16+12', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
overlay(
|
||||
child: const TextField(
|
||||
decoration: const InputDecoration(
|
||||
icon: const Icon(Icons.phone),
|
||||
labelText: 'label',
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final double iconRight = tester.getTopRight(find.byType(Icon)).dx;
|
||||
expect(iconRight, equals(tester.getTopLeft(find.text('label')).dx));
|
||||
expect(iconRight, equals(tester.getTopLeft(find.byType(EditableText)).dx));
|
||||
// Per https://material.io/guidelines/components/text-fields.html#text-fields-layout
|
||||
// There's a 16 dps gap between the right edge of the icon and the text field's
|
||||
// container, and the 12dps more padding between the left edge of the container
|
||||
// and the left edge of the input and label.
|
||||
expect(iconRight + 28.0, equals(tester.getTopLeft(find.text('label')).dx));
|
||||
expect(iconRight + 28.0, equals(tester.getTopLeft(find.byType(EditableText)).dx));
|
||||
});
|
||||
|
||||
testWidgets('Collapsed hint text placement', (WidgetTester tester) async {
|
||||
|
||||
Reference in New Issue
Block a user