Add test for flexible_space_bar.0.dart (#157107)

Contributes to https://github.com/flutter/flutter/issues/130459

It adds a test for
- `examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart`
This commit is contained in:
Valentin Vignal 2024-10-21 23:17:14 +08:00 committed by GitHub
parent bcc3146185
commit 3405f11e5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 103 additions and 56 deletions

View File

@ -312,7 +312,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/selectable_region/selectable_region.0_test.dart', 'examples/api/test/material/selectable_region/selectable_region.0_test.dart',
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart', 'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart', 'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart', 'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
'examples/api/test/painting/star_border/star_border.0_test.dart', 'examples/api/test/painting/star_border/star_border.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart', 'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',

View File

@ -2,77 +2,83 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Flutter code sample for [FlexibleSpaceBar]. /// Flutter code sample for [FlexibleSpaceBar].
void main() => runApp(const MaterialApp(home: FlexibleSpaceBarExampleApp())); void main() => runApp(const FlexibleSpaceBarExampleApp());
class FlexibleSpaceBarExampleApp extends StatelessWidget { class FlexibleSpaceBarExampleApp extends StatelessWidget {
const FlexibleSpaceBarExampleApp({super.key}); const FlexibleSpaceBarExampleApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return MaterialApp(
body: CustomScrollView( scrollBehavior: const MaterialScrollBehavior().copyWith(
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), dragDevices: PointerDeviceKind.values.toSet(),
slivers: <Widget>[ ),
SliverAppBar( home: Scaffold(
stretch: true, body: CustomScrollView(
onStretchTrigger: () { physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
// Function callback for stretch slivers: <Widget>[
return Future<void>.value(); SliverAppBar(
}, stretch: true,
expandedHeight: 300.0, onStretchTrigger: () {
flexibleSpace: FlexibleSpaceBar( // Function callback for stretch
stretchModes: const <StretchMode>[ return Future<void>.value();
StretchMode.zoomBackground, },
StretchMode.blurBackground, expandedHeight: 300.0,
StretchMode.fadeTitle, flexibleSpace: FlexibleSpaceBar(
], stretchModes: const <StretchMode>[
centerTitle: true, StretchMode.zoomBackground,
title: const Text('Flight Report'), StretchMode.blurBackground,
background: Stack( StretchMode.fadeTitle,
fit: StackFit.expand, ],
children: <Widget>[ centerTitle: true,
Image.network( title: const Text('Flight Report'),
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg', background: Stack(
fit: BoxFit.cover, fit: StackFit.expand,
), children: <Widget>[
const DecoratedBox( Image.network(
decoration: BoxDecoration( 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg',
gradient: LinearGradient( fit: BoxFit.cover,
begin: Alignment(0.0, 0.5), ),
end: Alignment.center, const DecoratedBox(
colors: <Color>[ decoration: BoxDecoration(
Color(0x60000000), gradient: LinearGradient(
Color(0x00000000), begin: Alignment(0.0, 0.5),
], end: Alignment.center,
colors: <Color>[
Color(0x60000000),
Color(0x00000000),
],
),
), ),
), ),
],
),
),
),
SliverList(
delegate: SliverChildListDelegate(
const <Widget>[
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Sunday'),
subtitle: Text('sunny, h: 80, l: 65'),
), ),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Monday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
// ListTiles++
], ],
), ),
), ),
), ],
SliverList( ),
delegate: SliverChildListDelegate(
const <Widget>[
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Sunday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Monday'),
subtitle: Text('sunny, h: 80, l: 65'),
),
// ListTiles++
],
),
),
],
), ),
); );
} }

View File

@ -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 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/flexible_space_bar/flexible_space_bar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
// The app being tested loads images via HTTP which the test
// framework defeats by default.
setUpAll(() {
HttpOverrides.global = null;
});
testWidgets('The app bar stretches when over-scrolled', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FlexibleSpaceBarExampleApp(),
);
expect(find.text('Flight Report'), findsOne);
expect(find.widgetWithText(ListTile, 'Sunday'), findsOne);
expect(find.widgetWithText(ListTile, 'Monday'), findsOne);
expect(find.text('sunny, h: 80, l: 65'), findsExactly(2));
expect(find.byIcon(Icons.wb_sunny), findsExactly(2));
final Finder appBarContainer = find.byType(Image);
final Size sizeBeforeScroll = tester.getSize(appBarContainer);
final Offset target = tester.getCenter(find.byType(ListTile).first);
final TestGesture gesture = await tester.startGesture(target);
await gesture.moveBy(const Offset(0.0, 100.0));
await tester.pump(const Duration(milliseconds: 10));
await gesture.up();
final Size sizeAfterScroll = tester.getSize(appBarContainer);
expect(sizeBeforeScroll.height, lessThan(sizeAfterScroll.height));
// Verifies ScrollBehavior.dragDevices is correctly set.
}, variant: TargetPlatformVariant.all());
}