Adjust and refactor all FlatButton tests into its respective file (#43742)
* Adjust and refactor all FlatButton tests into its respective file
This commit is contained in:
committed by
Shi-Hao Hong
parent
55df81e8eb
commit
3390e162cf
@@ -16,83 +16,6 @@ void main() {
|
||||
debugResetSemanticsIdCounter();
|
||||
});
|
||||
|
||||
testWidgets('FlatButton defaults', (WidgetTester tester) async {
|
||||
final Finder rawButtonMaterial = find.descendant(
|
||||
of: find.byType(FlatButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
|
||||
// Enabled FlatButton
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
Material material = tester.widget<Material>(rawButtonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0xdd000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(FlatButton));
|
||||
await tester.startGesture(center);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
material = tester.widget<Material>(rawButtonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0xdd000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
|
||||
// Disabled FlatButton
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
onPressed: null,
|
||||
child: Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
material = tester.widget<Material>(rawButtonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0x61000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
});
|
||||
|
||||
testWidgets('RaisedButton defaults', (WidgetTester tester) async {
|
||||
final Finder rawButtonMaterial = find.descendant(
|
||||
of: find.byType(RaisedButton),
|
||||
@@ -250,7 +173,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
child: OutlineButton(
|
||||
hoverColor: hoverColor,
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
@@ -260,27 +183,11 @@ void main() {
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(FlatButton)));
|
||||
await gesture.moveTo(tester.getCenter(find.byType(OutlineButton)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: hoverColor));
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: OutlineButton(
|
||||
hoverColor: hoverColor,
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: hoverColor));
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
@@ -302,11 +209,11 @@ void main() {
|
||||
testWidgets('Do buttons work with focus', (WidgetTester tester) async {
|
||||
const Color focusColor = Color(0xff001122);
|
||||
|
||||
FocusNode focusNode = FocusNode(debugLabel: 'FlatButton Node');
|
||||
FocusNode focusNode = FocusNode(debugLabel: 'RaisedButton Node');
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
child: RaisedButton(
|
||||
focusColor: focusColor,
|
||||
focusNode: focusNode,
|
||||
onPressed: () { },
|
||||
@@ -322,23 +229,6 @@ void main() {
|
||||
RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: focusColor));
|
||||
|
||||
focusNode = FocusNode(debugLabel: 'RaisedButton Node');
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: RaisedButton(
|
||||
focusColor: focusColor,
|
||||
focusNode: focusNode,
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
focusNode.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: focusColor));
|
||||
|
||||
focusNode = FocusNode(debugLabel: 'OutlineButton Node');
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
@@ -357,47 +247,6 @@ void main() {
|
||||
expect(inkFeatures, paints..rect(color: focusColor));
|
||||
});
|
||||
|
||||
testWidgets('Does FlatButton contribute semantics', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(semantics, hasSemantics(
|
||||
TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
TestSemantics.rootChild(
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
],
|
||||
label: 'ABC',
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 88.0, 48.0),
|
||||
transform: Matrix4.translationValues(356.0, 276.0, 0.0),
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isButton,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocusable,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
ignoreId: true,
|
||||
));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Does RaisedButton contribute semantics', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
await tester.pumpWidget(
|
||||
@@ -439,121 +288,6 @@ void main() {
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Does FlatButton scale with font scale changes', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 1.0),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 48.0)));
|
||||
expect(tester.getSize(find.byType(Text)), equals(const Size(42.0, 14.0)));
|
||||
|
||||
// textScaleFactor expands text, but not button.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 1.3),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 48.0)));
|
||||
// Scaled text rendering is different on Linux and Mac by one pixel.
|
||||
// TODO(gspencergoog): Figure out why this is, and fix it. https://github.com/flutter/flutter/issues/12357
|
||||
expect(tester.getSize(find.byType(Text)).width, isIn(<double>[54.0, 55.0]));
|
||||
expect(tester.getSize(find.byType(Text)).height, isIn(<double>[18.0, 19.0]));
|
||||
|
||||
// Set text scale large enough to expand text and button.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 3.0),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Scaled text rendering is different on Linux and Mac by one pixel.
|
||||
// TODO(gspencergoog): Figure out why this is, and fix it. https://github.com/flutter/flutter/issues/12357
|
||||
expect(tester.getSize(find.byType(FlatButton)).width, isIn(<double>[158.0, 159.0]));
|
||||
expect(tester.getSize(find.byType(FlatButton)).height, equals(48.0));
|
||||
expect(tester.getSize(find.byType(Text)).width, isIn(<double>[126.0, 127.0]));
|
||||
expect(tester.getSize(find.byType(Text)).height, equals(42.0));
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('FlatButton size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
|
||||
final Key key1 = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
key: key1,
|
||||
child: const SizedBox(width: 50.0, height: 8.0),
|
||||
onPressed: () { },
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(key1)), const Size(88.0, 48.0));
|
||||
|
||||
final Key key2 = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
key: key2,
|
||||
child: const SizedBox(width: 50.0, height: 8.0),
|
||||
onPressed: () { },
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(key2)), const Size(88.0, 36.0));
|
||||
});
|
||||
|
||||
testWidgets('RaisedButton size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
|
||||
final Key key1 = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -8,8 +8,86 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FlatButton defaults', (WidgetTester tester) async {
|
||||
final Finder rawButtonMaterial = find.descendant(
|
||||
of: find.byType(FlatButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
|
||||
// Enabled FlatButton
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
Material material = tester.widget<Material>(rawButtonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0xdd000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(FlatButton));
|
||||
await tester.startGesture(center);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
material = tester.widget<Material>(rawButtonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0xdd000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
|
||||
// Disabled FlatButton
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
onPressed: null,
|
||||
child: Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
material = tester.widget<Material>(rawButtonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, null);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, const Color(0xff000000));
|
||||
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
|
||||
expect(material.textStyle.color, const Color(0x61000000));
|
||||
expect(material.textStyle.fontFamily, 'Roboto');
|
||||
expect(material.textStyle.fontSize, 14);
|
||||
expect(material.textStyle.fontWeight, FontWeight.w500);
|
||||
expect(material.type, MaterialType.transparency);
|
||||
});
|
||||
|
||||
testWidgets('FlatButton implements debugFillProperties', (WidgetTester tester) async {
|
||||
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
||||
FlatButton(
|
||||
@@ -334,8 +412,212 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('FlatButton onPressed and onLongPress callbacks are correctly called when non-null', (WidgetTester tester) async {
|
||||
testWidgets('Does FlatButton work with hover', (WidgetTester tester) async {
|
||||
const Color hoverColor = Color(0xff001122);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
hoverColor: hoverColor,
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(FlatButton)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: hoverColor));
|
||||
|
||||
await gesture.removePointer();
|
||||
});
|
||||
|
||||
testWidgets('Does FlatButton work with focus', (WidgetTester tester) async {
|
||||
const Color focusColor = Color(0xff001122);
|
||||
|
||||
final FocusNode focusNode = FocusNode(debugLabel: 'FlatButton Node');
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FlatButton(
|
||||
focusColor: focusColor,
|
||||
focusNode: focusNode,
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
WidgetsBinding.instance.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
||||
focusNode.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paints..rect(color: focusColor));
|
||||
});
|
||||
|
||||
testWidgets('Does FlatButton contribute semantics', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(semantics, hasSemantics(
|
||||
TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
TestSemantics.rootChild(
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
],
|
||||
label: 'ABC',
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 88.0, 48.0),
|
||||
transform: Matrix4.translationValues(356.0, 276.0, 0.0),
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isButton,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocusable,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
ignoreId: true,
|
||||
));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Does FlatButton scale with font scale changes', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 1.0),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 48.0)));
|
||||
expect(tester.getSize(find.byType(Text)), equals(const Size(42.0, 14.0)));
|
||||
|
||||
// textScaleFactor expands text, but not button.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 1.3),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 48.0)));
|
||||
// Scaled text rendering is different on Linux and Mac by one pixel.
|
||||
// TODO(gspencergoog): Figure out why this is, and fix it. https://github.com/flutter/flutter/issues/12357
|
||||
expect(tester.getSize(find.byType(Text)).width, isIn(<double>[54.0, 55.0]));
|
||||
expect(tester.getSize(find.byType(Text)).height, isIn(<double>[18.0, 19.0]));
|
||||
|
||||
// Set text scale large enough to expand text and button.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(textScaleFactor: 3.0),
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
onPressed: () { },
|
||||
child: const Text('ABC'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Scaled text rendering is different on Linux and Mac by one pixel.
|
||||
// TODO(gspencergoog): Figure out why this is, and fix it. https://github.com/flutter/flutter/issues/12357
|
||||
expect(tester.getSize(find.byType(FlatButton)).width, isIn(<double>[158.0, 159.0]));
|
||||
expect(tester.getSize(find.byType(FlatButton)).height, equals(48.0));
|
||||
expect(tester.getSize(find.byType(Text)).width, isIn(<double>[126.0, 127.0]));
|
||||
expect(tester.getSize(find.byType(Text)).height, equals(42.0));
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('FlatButton size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
|
||||
final Key key1 = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
key: key1,
|
||||
child: const SizedBox(width: 50.0, height: 8.0),
|
||||
onPressed: () { },
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(key1)), const Size(88.0, 48.0));
|
||||
|
||||
final Key key2 = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: FlatButton(
|
||||
key: key2,
|
||||
child: const SizedBox(width: 50.0, height: 8.0),
|
||||
onPressed: () { },
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(key2)), const Size(88.0, 36.0));
|
||||
});
|
||||
|
||||
testWidgets('FlatButton onPressed and onLongPress callbacks are correctly called when non-null', (WidgetTester tester) async {
|
||||
bool wasPressed;
|
||||
Finder flatButton;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user