Skip to content

Commit 708f53a

Browse files
blerouxlucaantonelli
authored andcommitted
Add missing M3 tests for InputDecoration.floatingLabelAlignment (flutter#170903)
## Description This PR adds missing M3 tests for InputDecoration.floatingLabelAlignment. ## Related Issue Will help to complete flutter#168981 ## Tests Adds 8 tests (based on existing M2 tests).
1 parent b45749c commit 708f53a

1 file changed

Lines changed: 214 additions & 0 deletions

File tree

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7618,6 +7618,220 @@ void main() {
76187618
});
76197619
});
76207620

7621+
group('Material3 - InputDecoration floatingLabelAlignment', () {
7622+
Widget buildInputDecoratorWithFloatingLabel({
7623+
required TextDirection textDirection,
7624+
required bool hasIcon,
7625+
required FloatingLabelAlignment alignment,
7626+
bool borderIsOutline = false,
7627+
}) {
7628+
return buildInputDecorator(
7629+
textDirection: textDirection,
7630+
decoration: InputDecoration(
7631+
contentPadding: const EdgeInsetsDirectional.only(start: 40.0, top: 12.0, bottom: 12.0),
7632+
floatingLabelAlignment: alignment,
7633+
icon: hasIcon ? const Icon(Icons.insert_link) : null,
7634+
labelText: labelText,
7635+
hintText: hintText,
7636+
filled: true,
7637+
border: borderIsOutline ? const OutlineInputBorder() : null,
7638+
),
7639+
);
7640+
}
7641+
7642+
group('LTR with icon aligned', () {
7643+
testWidgets('start', (WidgetTester tester) async {
7644+
await tester.pumpWidget(
7645+
buildInputDecoratorWithFloatingLabel(
7646+
textDirection: TextDirection.ltr,
7647+
hasIcon: true,
7648+
alignment: FloatingLabelAlignment.start,
7649+
),
7650+
);
7651+
// icon (40) + contentPadding (40) + _kInputExtraPadding
7652+
expect(getLabelRect(tester).left, 84.0);
7653+
7654+
await tester.pumpWidget(
7655+
buildInputDecoratorWithFloatingLabel(
7656+
textDirection: TextDirection.ltr,
7657+
hasIcon: true,
7658+
alignment: FloatingLabelAlignment.start,
7659+
borderIsOutline: true,
7660+
),
7661+
);
7662+
// icon (40) + contentPadding (40) + _kInputExtraPadding
7663+
expect(getLabelRect(tester).left, 84.0);
7664+
});
7665+
7666+
testWidgets('center', (WidgetTester tester) async {
7667+
await tester.pumpWidget(
7668+
buildInputDecoratorWithFloatingLabel(
7669+
textDirection: TextDirection.ltr,
7670+
hasIcon: true,
7671+
alignment: FloatingLabelAlignment.center,
7672+
),
7673+
);
7674+
// icon (40) + (decorator (800) - icon (40)) / 2
7675+
expect(getLabelCenter(tester).dx, 420.0);
7676+
7677+
await tester.pumpWidget(
7678+
buildInputDecoratorWithFloatingLabel(
7679+
textDirection: TextDirection.ltr,
7680+
hasIcon: true,
7681+
alignment: FloatingLabelAlignment.center,
7682+
borderIsOutline: true,
7683+
),
7684+
);
7685+
// icon (40) + (decorator (800) - icon (40)) / 2
7686+
expect(getLabelCenter(tester).dx, 420.0);
7687+
});
7688+
});
7689+
7690+
group('LTR without icon aligned', () {
7691+
testWidgets('start', (WidgetTester tester) async {
7692+
await tester.pumpWidget(
7693+
buildInputDecoratorWithFloatingLabel(
7694+
textDirection: TextDirection.ltr,
7695+
hasIcon: false,
7696+
alignment: FloatingLabelAlignment.start,
7697+
),
7698+
);
7699+
// contentPadding (40) + _kInputExtraPadding
7700+
expect(getLabelRect(tester).left, 44.0);
7701+
7702+
await tester.pumpWidget(
7703+
buildInputDecoratorWithFloatingLabel(
7704+
textDirection: TextDirection.ltr,
7705+
hasIcon: false,
7706+
alignment: FloatingLabelAlignment.start,
7707+
borderIsOutline: true,
7708+
),
7709+
);
7710+
// contentPadding (40) + _kInputExtraPadding
7711+
expect(getLabelRect(tester).left, 44.0);
7712+
});
7713+
7714+
testWidgets('center', (WidgetTester tester) async {
7715+
await tester.pumpWidget(
7716+
buildInputDecoratorWithFloatingLabel(
7717+
textDirection: TextDirection.ltr,
7718+
hasIcon: false,
7719+
alignment: FloatingLabelAlignment.center,
7720+
),
7721+
);
7722+
// decorator (800) / 2
7723+
expect(getLabelCenter(tester).dx, 400.0);
7724+
7725+
await tester.pumpWidget(
7726+
buildInputDecoratorWithFloatingLabel(
7727+
textDirection: TextDirection.ltr,
7728+
hasIcon: false,
7729+
alignment: FloatingLabelAlignment.center,
7730+
borderIsOutline: true,
7731+
),
7732+
);
7733+
// decorator (800) / 2
7734+
expect(getLabelCenter(tester).dx, 400.0);
7735+
});
7736+
});
7737+
7738+
group('RTL with icon aligned', () {
7739+
testWidgets('start', (WidgetTester tester) async {
7740+
await tester.pumpWidget(
7741+
buildInputDecoratorWithFloatingLabel(
7742+
textDirection: TextDirection.rtl,
7743+
hasIcon: true,
7744+
alignment: FloatingLabelAlignment.start,
7745+
),
7746+
);
7747+
// decorator (800) - icon (40) - contentPadding (40) - _kInputExtraPadding
7748+
expect(getLabelRect(tester).right, 716.0);
7749+
7750+
await tester.pumpWidget(
7751+
buildInputDecoratorWithFloatingLabel(
7752+
textDirection: TextDirection.rtl,
7753+
hasIcon: true,
7754+
alignment: FloatingLabelAlignment.start,
7755+
borderIsOutline: true,
7756+
),
7757+
);
7758+
// decorator (800) - icon (40) - contentPadding (40) - _kInputExtraPadding
7759+
expect(getLabelRect(tester).right, 716.0);
7760+
});
7761+
7762+
testWidgets('center', (WidgetTester tester) async {
7763+
await tester.pumpWidget(
7764+
buildInputDecoratorWithFloatingLabel(
7765+
textDirection: TextDirection.rtl,
7766+
hasIcon: true,
7767+
alignment: FloatingLabelAlignment.center,
7768+
),
7769+
);
7770+
// (decorator (800) - icon (40)) / 2
7771+
expect(getLabelCenter(tester).dx, 380.0);
7772+
7773+
await tester.pumpWidget(
7774+
buildInputDecoratorWithFloatingLabel(
7775+
textDirection: TextDirection.rtl,
7776+
hasIcon: true,
7777+
alignment: FloatingLabelAlignment.center,
7778+
borderIsOutline: true,
7779+
),
7780+
);
7781+
// (decorator (800) - icon (40)) / 2
7782+
expect(getLabelCenter(tester).dx, 380.0);
7783+
});
7784+
});
7785+
7786+
group('RTL without icon aligned', () {
7787+
testWidgets('start', (WidgetTester tester) async {
7788+
await tester.pumpWidget(
7789+
buildInputDecoratorWithFloatingLabel(
7790+
textDirection: TextDirection.rtl,
7791+
hasIcon: false,
7792+
alignment: FloatingLabelAlignment.start,
7793+
),
7794+
);
7795+
// decorator (800) - contentPadding (40) - _kInputExtraPadding
7796+
expect(getLabelRect(tester).right, 756.0);
7797+
7798+
await tester.pumpWidget(
7799+
buildInputDecoratorWithFloatingLabel(
7800+
textDirection: TextDirection.rtl,
7801+
hasIcon: false,
7802+
alignment: FloatingLabelAlignment.start,
7803+
borderIsOutline: true,
7804+
),
7805+
);
7806+
// decorator (800) - contentPadding (40) - _kInputExtraPadding
7807+
expect(getLabelRect(tester).right, 756.0);
7808+
});
7809+
7810+
testWidgets('center', (WidgetTester tester) async {
7811+
await tester.pumpWidget(
7812+
buildInputDecoratorWithFloatingLabel(
7813+
textDirection: TextDirection.rtl,
7814+
hasIcon: false,
7815+
alignment: FloatingLabelAlignment.center,
7816+
),
7817+
);
7818+
// decorator (800) / 2
7819+
expect(getLabelCenter(tester).dx, 400.0);
7820+
7821+
await tester.pumpWidget(
7822+
buildInputDecoratorWithFloatingLabel(
7823+
textDirection: TextDirection.rtl,
7824+
hasIcon: false,
7825+
alignment: FloatingLabelAlignment.center,
7826+
borderIsOutline: true,
7827+
),
7828+
);
7829+
// decorator (800) / 2
7830+
expect(getLabelCenter(tester).dx, 400.0);
7831+
});
7832+
});
7833+
});
7834+
76217835
group('Material3 - InputDecoration isDense', () {
76227836
// M3 extra horizontal padding.
76237837
const double kInputExtraPadding = 4.0;

0 commit comments

Comments
 (0)