diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 499a06fd8c..e51b711ad3 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -433,10 +433,6 @@ final Set _knownMissingTests = { 'examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart', 'examples/api/test/widgets/scrollbar/raw_scrollbar.shape.0_test.dart', 'examples/api/test/widgets/scrollbar/raw_scrollbar.0_test.dart', - 'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart', - 'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart', - 'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart', - 'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart', 'examples/api/test/widgets/interactive_viewer/interactive_viewer.constrained.0_test.dart', 'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart', 'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart', diff --git a/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart new file mode 100644 index 0000000000..cb60dc3bf9 --- /dev/null +++ b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart @@ -0,0 +1,42 @@ +// 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_api_samples/widgets/sliver_fill/sliver_fill_remaining.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('shows how SliverFillRemaining takes up remaining space', (WidgetTester tester) async { + await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); + expect(find.text('SliverFillRemaining Sample'), findsOneWidget); + expect(find.byType(CustomScrollView), findsOneWidget); + + expect(find.descendant( + of: find.byType(SliverToBoxAdapter), + matching: find.byType(Container)), findsOneWidget); + final Container upperContainer = tester.widget(find.descendant( + of: find.byType(SliverToBoxAdapter), + matching: find.byType(Container))); + expect(upperContainer.color, Colors.amber[300]); + + expect(find.byType(SliverFillRemaining), findsOneWidget); + expect(find.descendant( + of: find.byType(SliverFillRemaining), + matching: find.byType(Container)), findsOneWidget); + expect(find.byIcon(Icons.sentiment_very_satisfied), findsOneWidget); + final Icon lowerIcon = tester.widget(find.descendant( + of: find.byType(SliverFillRemaining), + matching: find.byType(Icon))); + expect(lowerIcon.color, Colors.blue[900]); + + final double total = tester.getSize(find.byType(CustomScrollView)).height; + final double upperHeight = tester.getSize(find.descendant( + of: find.byType(SliverToBoxAdapter), + matching: find.byType(Container))).height; + final double lowerHeight = tester.getSize(find.descendant( + of: find.byType(SliverFillRemaining), + matching: find.byType(Icon))).height; + expect(upperHeight + lowerHeight, equals(total)); + }); +} diff --git a/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart new file mode 100644 index 0000000000..de66a3ea69 --- /dev/null +++ b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart @@ -0,0 +1,43 @@ +// 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_api_samples/widgets/sliver_fill/sliver_fill_remaining.1.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Shows all elements', (WidgetTester tester) async { + await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); + expect(find.text('SliverFillRemaining Sample'), findsOneWidget); + expect(find.byType(CustomScrollView), findsOneWidget); + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.amber[200]), + findsNWidgets(2)); + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.blue[200]), + findsOneWidget); + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.orange[300]), + findsOneWidget); + expect(find.byType(SliverFixedExtentList), findsOneWidget); + expect(find.byType(SliverFillRemaining), findsOneWidget); + expect(find.byType(FlutterLogo), findsOneWidget); + }); + + testWidgets('Fills up all available space', (WidgetTester tester) async { + await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); + + final double listSpace = tester.getSize(find.byType(CustomScrollView)).height; + double contentHeight = 0.0; + for (final Widget widget in tester.widgetList(find.byWidgetPredicate( + (Widget widget) => + (widget is Container) + && [Colors.orange[300]!, Colors.blue[200]!, Colors.amber[200]!] + .contains(widget.color))) + ) { + contentHeight += tester.getSize(find.byWidget(widget)).height; + } + expectLater(contentHeight, equals(listSpace)); + }); +} diff --git a/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart new file mode 100644 index 0000000000..5d3a5535de --- /dev/null +++ b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart @@ -0,0 +1,31 @@ +// 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_api_samples/widgets/sliver_fill/sliver_fill_remaining.2.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Shows all elements', (WidgetTester tester) async { + await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); + expect(find.text('SliverFillRemaining Sample'), findsOneWidget); + expect(find.byType(CustomScrollView), findsOneWidget); + expect(find.byType(SliverFixedExtentList), findsOneWidget); + + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.indigo[200], + skipOffstage: false, + ), findsNWidgets(3)); + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.orange[200] + ), findsNWidgets(2)); + expect(find.byType(Container, skipOffstage: false,), findsNWidgets(5)); + + expect(find.byType(SliverFillRemaining), findsNothing); + await tester.scrollUntilVisible(find.byType(SliverFillRemaining), 20); + expect(find.byType(SliverFillRemaining), findsOneWidget); + expect(find.byIcon(Icons.pan_tool), findsOneWidget); + expect(tester.widget(find.byIcon(Icons.pan_tool)).color, Colors.blueGrey); + }); +} diff --git a/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart new file mode 100644 index 0000000000..fbd88e9f1f --- /dev/null +++ b/examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart @@ -0,0 +1,33 @@ +// 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_api_samples/widgets/sliver_fill/sliver_fill_remaining.3.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Shows all elements', (WidgetTester tester) async { + await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); + expect(find.text('SliverFillRemaining Sample'), findsOneWidget); + expect(find.byType(ElevatedButton), findsOneWidget); + expect(find.text('Bottom Pinned Button!'), findsOneWidget); + expect(find.byType(CustomScrollView), findsOneWidget); + final CustomScrollView scroll = tester.widget(find.byType(CustomScrollView)); + expect(scroll.physics, isA(). + having((BouncingScrollPhysics bsp) => bsp.parent, 'parent', isA())); + + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.tealAccent[700], + ), findsOneWidget); + expect(find.byWidgetPredicate((Widget widget) => (widget is Container) + && widget.color == Colors.teal[100] + ), findsOneWidget); + expect(find.byType(Container), findsNWidgets(2)); + + expect(find.byType(SliverFillRemaining), findsOneWidget); + final SliverFillRemaining fill = tester.widget(find.byType(SliverFillRemaining)); + expect(fill.hasScrollBody, false); + expect(fill.fillOverscroll, true); + }); +}