Update ListTile test to prevent log dump and test error message. (#161811)
Fixes [`ListTile` widget tests dump logs in Flutter CI](https://github.com/flutter/flutter/issues/161810) ### Before <img width="1341" alt="Screenshot 2025-01-17 at 17 37 30" src="https://github.com/user-attachments/assets/fa3a6b46-07ae-4f41-9f8c-821943acdd4c" /> ### After <img width="1341" alt="Screenshot 2025-01-17 at 17 36 50" src="https://github.com/user-attachments/assets/6ffd2d19-fa61-4dc5-b5e7-bb0fc8c07008" /> ## 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. - [ ] 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]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] 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
This commit is contained in:
@@ -2621,6 +2621,12 @@ void main() {
|
||||
testWidgets('Leading/Trailing exceeding list tile width throws exception', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
List<dynamic> exceptions = <dynamic>[];
|
||||
FlutterExceptionHandler? oldHandler = FlutterError.onError;
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
exceptions.add(details.exception);
|
||||
};
|
||||
|
||||
Widget buildListTile({Widget? leading, Widget? trailing}) {
|
||||
return MaterialApp(
|
||||
home: Material(
|
||||
@@ -2636,16 +2642,56 @@ void main() {
|
||||
// List tile width is 100 as a result, an exception should be thrown.
|
||||
await tester.pumpWidget(buildListTile(leading: const SizedBox(width: 61)));
|
||||
|
||||
// Error message cannot be tested as there too many errors thrown.
|
||||
expect(tester.takeException(), isNotNull);
|
||||
FlutterError.onError = oldHandler;
|
||||
expect(exceptions.first.runtimeType, FlutterError);
|
||||
FlutterError error = exceptions.first as FlutterError;
|
||||
expect(error.diagnostics.length, 3);
|
||||
expect(
|
||||
error.diagnostics[0].toStringDeep(),
|
||||
'Leading widget consumes the entire tile width (including\nListTile.contentPadding).\n',
|
||||
);
|
||||
expect(
|
||||
error.diagnostics[1].toStringDeep(),
|
||||
'Either resize the tile width so that the leading widget plus any\n'
|
||||
'content padding do not exceed the tile width, or use a sized\n'
|
||||
'widget, or consider replacing ListTile with a custom widget.\n',
|
||||
);
|
||||
expect(
|
||||
error.diagnostics[2].toStringDeep(),
|
||||
'See also:\n'
|
||||
'https://api.flutter.dev/flutter/material/ListTile-class.html#material.ListTile.4\n',
|
||||
);
|
||||
|
||||
exceptions = <dynamic>[];
|
||||
oldHandler = FlutterError.onError;
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
exceptions.add(details.exception);
|
||||
};
|
||||
|
||||
// Test a trailing widget that exceeds the list tile width.
|
||||
// 16 (content padding) + 61 (trailing width) + 24 (content padding) = 101.
|
||||
// List tile width is 100 as a result, an exception should be thrown.
|
||||
await tester.pumpWidget(buildListTile(trailing: const SizedBox(width: 61)));
|
||||
|
||||
// Error message cannot tested be as there too many errors thrown.
|
||||
expect(tester.takeException(), isNotNull);
|
||||
FlutterError.onError = oldHandler;
|
||||
expect(exceptions.first.runtimeType, FlutterError);
|
||||
error = exceptions.first as FlutterError;
|
||||
expect(error.diagnostics.length, 3);
|
||||
expect(
|
||||
error.diagnostics[0].toStringDeep(),
|
||||
'Trailing widget consumes the entire tile width (including\nListTile.contentPadding).\n',
|
||||
);
|
||||
expect(
|
||||
error.diagnostics[1].toStringDeep(),
|
||||
'Either resize the tile width so that the trailing widget plus any\n'
|
||||
'content padding do not exceed the tile width, or use a sized\n'
|
||||
'widget, or consider replacing ListTile with a custom widget.\n',
|
||||
);
|
||||
expect(
|
||||
error.diagnostics[2].toStringDeep(),
|
||||
'See also:\n'
|
||||
'https://api.flutter.dev/flutter/material/ListTile-class.html#material.ListTile.4\n',
|
||||
);
|
||||
});
|
||||
|
||||
group('Material 2', () {
|
||||
|
||||
Reference in New Issue
Block a user