Sangam Shrestha d261411b4c
Remove redundant useMaterial3: true (#163376)
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

This PR removes redundant useMaterial3: true as described in
https://github.com/flutter/flutter/issues/162818

*List which issues are fixed by this PR. You must list at least one
issue. An issue is not required if the PR fixes something trivial like a
typo.*

- https://github.com/flutter/flutter/issues/162818

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
2025-03-14 17:50:20 +00:00

220 lines
8.8 KiB
Dart

// Copyright 2014 The Flutter 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('Material3 - Divider control test', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: Divider())));
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
expect(box.size.height, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 1.0);
});
testWidgets('Material2 - Divider control test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(theme: ThemeData(useMaterial3: false), home: const Center(child: Divider())),
);
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
expect(box.size.height, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 0.0);
});
testWidgets('Divider custom thickness', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Divider(thickness: 5.0)),
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 5.0);
});
testWidgets('Divider custom radius', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Divider(radius: BorderRadius.circular(5))),
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.bottomLeft, const Radius.circular(5));
expect(borderRadius.bottomRight, const Radius.circular(5));
expect(borderRadius.topLeft, const Radius.circular(5));
expect(borderRadius.topRight, const Radius.circular(5));
});
testWidgets('Horizontal divider custom indentation', (WidgetTester tester) async {
const double customIndent = 10.0;
Rect dividerRect;
Rect lineRect;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Divider(indent: customIndent)),
),
);
// The divider line is drawn with a DecoratedBox with a border
dividerRect = tester.getRect(find.byType(Divider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left + customIndent);
expect(lineRect.right, dividerRect.right);
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Divider(endIndent: customIndent)),
),
);
dividerRect = tester.getRect(find.byType(Divider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left);
expect(lineRect.right, dividerRect.right - customIndent);
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Divider(indent: customIndent, endIndent: customIndent)),
),
);
dividerRect = tester.getRect(find.byType(Divider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left + customIndent);
expect(lineRect.right, dividerRect.right - customIndent);
});
testWidgets('Material3 - Vertical Divider Test', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: VerticalDivider())));
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
expect(box.size.width, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 1.0);
});
testWidgets('Material2 - Vertical Divider Test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Center(child: VerticalDivider()),
),
);
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
expect(box.size.width, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 0.0);
});
testWidgets('Divider custom thickness', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: VerticalDivider(thickness: 5.0)),
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 5.0);
});
testWidgets('Vertical Divider Test 2', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Material(
child: SizedBox(
height: 24.0,
child: Row(children: <Widget>[Text('Hey.'), VerticalDivider()]),
),
),
),
);
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
final RenderBox containerBox = tester.firstRenderObject(find.byType(Container).last);
expect(box.size.width, 16.0);
expect(containerBox.size.height, 600.0);
expect(find.byType(VerticalDivider), paints..path(strokeWidth: 0.0));
});
testWidgets('Vertical divider custom indentation', (WidgetTester tester) async {
const double customIndent = 10.0;
Rect dividerRect;
Rect lineRect;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: VerticalDivider(indent: customIndent)),
),
);
// The divider line is drawn with a DecoratedBox with a border
dividerRect = tester.getRect(find.byType(VerticalDivider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top + customIndent);
expect(lineRect.bottom, dividerRect.bottom);
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: VerticalDivider(endIndent: customIndent)),
),
);
dividerRect = tester.getRect(find.byType(VerticalDivider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top);
expect(lineRect.bottom, dividerRect.bottom - customIndent);
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: VerticalDivider(indent: customIndent, endIndent: customIndent)),
),
);
dividerRect = tester.getRect(find.byType(VerticalDivider));
lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top + customIndent);
expect(lineRect.bottom, dividerRect.bottom - customIndent);
});
testWidgets('VerticalDivider custom radius', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(child: VerticalDivider(radius: BorderRadius.circular(5))),
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.bottomLeft, const Radius.circular(5));
expect(borderRadius.bottomRight, const Radius.circular(5));
expect(borderRadius.topLeft, const Radius.circular(5));
expect(borderRadius.topRight, const Radius.circular(5));
});
// Regression test for https://github.com/flutter/flutter/issues/39533
testWidgets('createBorderSide does not throw exception with null context', (
WidgetTester tester,
) async {
// Passing a null context used to throw an exception but no longer does.
expect(() => Divider.createBorderSide(null), isNot(throwsAssertionError));
expect(() => Divider.createBorderSide(null), isNot(throwsNoSuchMethodError));
});
}