mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
WIP Commits separated as follows: - Update lints in analysis_options files - Run `dart fix --apply` - Clean up leftover analysis issues - Run `dart format .` in the right places. Local analysis and testing passes. Checking CI now. Part of https://github.com/flutter/flutter/issues/178827 - Adoption of flutter_lints in examples/api coming in a separate change (cc @loic-sharma) ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] 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]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- 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
394 lines
15 KiB
Dart
394 lines
15 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/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
test('DividerThemeData copyWith, ==, hashCode basics', () {
|
|
expect(const DividerThemeData(), const DividerThemeData().copyWith());
|
|
expect(const DividerThemeData().hashCode, const DividerThemeData().copyWith().hashCode);
|
|
});
|
|
|
|
test('DividerThemeData null fields by default', () {
|
|
const dividerTheme = DividerThemeData();
|
|
expect(dividerTheme.color, null);
|
|
expect(dividerTheme.space, null);
|
|
expect(dividerTheme.thickness, null);
|
|
expect(dividerTheme.indent, null);
|
|
expect(dividerTheme.endIndent, null);
|
|
expect(dividerTheme.radius, null);
|
|
});
|
|
|
|
testWidgets('Default DividerThemeData debugFillProperties', (WidgetTester tester) async {
|
|
final builder = DiagnosticPropertiesBuilder();
|
|
const DividerThemeData().debugFillProperties(builder);
|
|
|
|
final List<String> description = builder.properties
|
|
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
|
|
.map((DiagnosticsNode node) => node.toString())
|
|
.toList();
|
|
|
|
expect(description, <String>[]);
|
|
});
|
|
|
|
testWidgets('DividerThemeData implements debugFillProperties', (WidgetTester tester) async {
|
|
final builder = DiagnosticPropertiesBuilder();
|
|
const DividerThemeData(
|
|
color: Color(0xFFFFFFFF),
|
|
space: 5.0,
|
|
thickness: 4.0,
|
|
indent: 3.0,
|
|
endIndent: 2.0,
|
|
radius: BorderRadius.all(Radius.circular(20)),
|
|
).debugFillProperties(builder);
|
|
|
|
final List<String> description = builder.properties
|
|
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
|
|
.map((DiagnosticsNode node) => node.toString())
|
|
.toList();
|
|
|
|
expect(description, <String>[
|
|
'color: ${const Color(0xffffffff)}',
|
|
'space: 5.0',
|
|
'thickness: 4.0',
|
|
'indent: 3.0',
|
|
'endIndent: 2.0',
|
|
'radius: BorderRadius.circular(20.0)',
|
|
]);
|
|
});
|
|
|
|
group('Material3 - Horizontal Divider', () {
|
|
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
|
|
final theme = ThemeData();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: theme,
|
|
home: const Scaffold(body: Divider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
|
|
expect(box.size.height, 16.0);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, 1.0);
|
|
|
|
expect(decoration.border!.bottom.color, theme.colorScheme.outlineVariant);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(Divider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.left, dividerRect.left);
|
|
expect(lineRect.right, dividerRect.right);
|
|
});
|
|
|
|
testWidgets('Uses values from DividerThemeData', (WidgetTester tester) async {
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(dividerTheme: dividerTheme),
|
|
home: const Scaffold(body: Divider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
|
|
expect(box.size.height, dividerTheme.space);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, dividerTheme.thickness);
|
|
expect(decoration.border!.bottom.color, dividerTheme.color);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(Divider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.left, dividerRect.left + dividerTheme.indent!);
|
|
expect(lineRect.right, dividerRect.right - dividerTheme.endIndent!);
|
|
|
|
final borderRadius = decoration.borderRadius! as BorderRadius;
|
|
expect(borderRadius.topLeft, const Radius.circular(1));
|
|
expect(borderRadius.topRight, const Radius.circular(2));
|
|
expect(borderRadius.bottomLeft, const Radius.circular(3));
|
|
expect(borderRadius.bottomRight, const Radius.circular(4));
|
|
});
|
|
|
|
testWidgets('DividerTheme overrides defaults', (WidgetTester tester) async {
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DividerTheme(data: dividerTheme, child: const Divider()),
|
|
),
|
|
),
|
|
);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, dividerTheme.thickness);
|
|
expect(decoration.border!.bottom.color, dividerTheme.color);
|
|
});
|
|
|
|
testWidgets('Widget properties take priority over theme', (WidgetTester tester) async {
|
|
const Color color = Colors.purple;
|
|
const height = 10.0;
|
|
const thickness = 5.0;
|
|
const indent = 8.0;
|
|
const endIndent = 9.0;
|
|
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(dividerTheme: dividerTheme),
|
|
home: const Scaffold(
|
|
body: Divider(
|
|
color: color,
|
|
height: height,
|
|
thickness: thickness,
|
|
indent: indent,
|
|
endIndent: endIndent,
|
|
radius: BorderRadiusGeometry.all(Radius.circular(5)),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
|
|
expect(box.size.height, height);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, thickness);
|
|
expect(decoration.border!.bottom.color, color);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(Divider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.left, dividerRect.left + indent);
|
|
expect(lineRect.right, dividerRect.right - endIndent);
|
|
|
|
final borderRadius = decoration.borderRadius! as BorderRadius;
|
|
expect(borderRadius.topLeft, const Radius.circular(5));
|
|
expect(borderRadius.topRight, const Radius.circular(5));
|
|
expect(borderRadius.bottomLeft, const Radius.circular(5));
|
|
expect(borderRadius.bottomRight, const Radius.circular(5));
|
|
});
|
|
});
|
|
|
|
group('Material3 - Vertical Divider', () {
|
|
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
|
|
final theme = ThemeData();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: theme,
|
|
home: const Scaffold(body: VerticalDivider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
|
|
expect(box.size.width, 16.0);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
final border = decoration.border! as Border;
|
|
expect(border.left.width, 1.0);
|
|
|
|
expect(border.left.color, theme.colorScheme.outlineVariant);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(VerticalDivider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.top, dividerRect.top);
|
|
expect(lineRect.bottom, dividerRect.bottom);
|
|
});
|
|
|
|
testWidgets('Uses values from DividerThemeData', (WidgetTester tester) async {
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(dividerTheme: dividerTheme),
|
|
home: const Scaffold(body: VerticalDivider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
|
|
expect(box.size.width, dividerTheme.space);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
final border = decoration.border! as Border;
|
|
expect(border.left.width, dividerTheme.thickness);
|
|
expect(border.left.color, dividerTheme.color);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(VerticalDivider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.top, dividerRect.top + dividerTheme.indent!);
|
|
expect(lineRect.bottom, dividerRect.bottom - dividerTheme.endIndent!);
|
|
|
|
final borderRadius = decoration.borderRadius! as BorderRadius;
|
|
expect(borderRadius.topLeft, const Radius.circular(1));
|
|
expect(borderRadius.topRight, const Radius.circular(2));
|
|
expect(borderRadius.bottomLeft, const Radius.circular(3));
|
|
expect(borderRadius.bottomRight, const Radius.circular(4));
|
|
});
|
|
|
|
testWidgets('DividerTheme overrides defaults', (WidgetTester tester) async {
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DividerTheme(data: dividerTheme, child: const VerticalDivider()),
|
|
),
|
|
),
|
|
);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
final border = decoration.border! as Border;
|
|
expect(border.left.width, dividerTheme.thickness);
|
|
expect(border.left.color, dividerTheme.color);
|
|
});
|
|
|
|
testWidgets('Widget properties take priority over theme', (WidgetTester tester) async {
|
|
const Color color = Colors.purple;
|
|
const width = 10.0;
|
|
const thickness = 5.0;
|
|
const indent = 8.0;
|
|
const endIndent = 9.0;
|
|
|
|
final DividerThemeData dividerTheme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(dividerTheme: dividerTheme),
|
|
home: const Scaffold(
|
|
body: VerticalDivider(
|
|
color: color,
|
|
width: width,
|
|
thickness: thickness,
|
|
indent: indent,
|
|
endIndent: endIndent,
|
|
radius: BorderRadiusGeometry.all(Radius.circular(5)),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
|
|
expect(box.size.width, width);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
final border = decoration.border! as Border;
|
|
expect(border.left.width, thickness);
|
|
expect(border.left.color, color);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(VerticalDivider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.top, dividerRect.top + indent);
|
|
expect(lineRect.bottom, dividerRect.bottom - endIndent);
|
|
|
|
final borderRadius = decoration.borderRadius! as BorderRadius;
|
|
expect(borderRadius.topLeft, const Radius.circular(5));
|
|
expect(borderRadius.topRight, const Radius.circular(5));
|
|
expect(borderRadius.bottomLeft, const Radius.circular(5));
|
|
expect(borderRadius.bottomRight, const Radius.circular(5));
|
|
});
|
|
});
|
|
|
|
group('Material 2', () {
|
|
// These tests are only relevant for Material 2. Once Material 2
|
|
// support is deprecated and the APIs are removed, these tests
|
|
// can be deleted.
|
|
|
|
group('Material2 - Horizontal Divider', () {
|
|
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(useMaterial3: false),
|
|
home: const Scaffold(body: Divider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
|
|
expect(box.size.height, 16.0);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, 0.0);
|
|
|
|
final theme = ThemeData(useMaterial3: false);
|
|
expect(decoration.border!.bottom.color, theme.dividerColor);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(Divider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.left, dividerRect.left);
|
|
expect(lineRect.right, dividerRect.right);
|
|
});
|
|
|
|
testWidgets('DividerTheme overrides defaults', (WidgetTester tester) async {
|
|
final DividerThemeData theme = _dividerTheme();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: DividerTheme(data: theme, child: const Divider()),
|
|
),
|
|
),
|
|
);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
expect(decoration.border!.bottom.width, theme.thickness);
|
|
expect(decoration.border!.bottom.color, theme.color);
|
|
|
|
final borderRadius = decoration.borderRadius! as BorderRadius;
|
|
expect(borderRadius.topLeft, const Radius.circular(1));
|
|
expect(borderRadius.topRight, const Radius.circular(2));
|
|
expect(borderRadius.bottomLeft, const Radius.circular(3));
|
|
expect(borderRadius.bottomRight, const Radius.circular(4));
|
|
});
|
|
});
|
|
|
|
group('Material2 - Vertical Divider', () {
|
|
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(useMaterial3: false),
|
|
home: const Scaffold(body: VerticalDivider()),
|
|
),
|
|
);
|
|
|
|
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
|
|
expect(box.size.width, 16.0);
|
|
|
|
final Container container = tester.widget(find.byType(Container));
|
|
final decoration = container.decoration! as BoxDecoration;
|
|
final border = decoration.border! as Border;
|
|
expect(border.left.width, 0.0);
|
|
|
|
final theme = ThemeData(useMaterial3: false);
|
|
expect(border.left.color, theme.dividerColor);
|
|
|
|
final Rect dividerRect = tester.getRect(find.byType(VerticalDivider));
|
|
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
|
|
expect(lineRect.top, dividerRect.top);
|
|
expect(lineRect.bottom, dividerRect.bottom);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
DividerThemeData _dividerTheme() {
|
|
return const DividerThemeData(
|
|
color: Colors.orange,
|
|
space: 12.0,
|
|
thickness: 2.0,
|
|
indent: 7.0,
|
|
endIndent: 5.0,
|
|
radius: BorderRadiusGeometry.only(
|
|
topLeft: Radius.circular(1),
|
|
topRight: Radius.circular(2),
|
|
bottomLeft: Radius.circular(3),
|
|
bottomRight: Radius.circular(4),
|
|
),
|
|
);
|
|
}
|