Skip to content

Commit e467289

Browse files
authored
Fix DecoratedSliver sample code to reflect the description (#148621)
### Demo screenshot ![Screenshot 2024-05-19 at 05 42 35](https://github.com/flutter/flutter/assets/104349824/6b4aec1f-32ab-496e-ab20-458c2051055d) ### Related issue - Fixes flutter/flutter#145935 - Add test for `examples/api/test/widgets/sliver/decorated_sliver.0_test.dart` as a part of flutter/flutter#130459.
1 parent abad372 commit e467289

File tree

3 files changed

+131
-10
lines changed

3 files changed

+131
-10
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ final Set<String> _knownMissingTests = <String>{
376376
'examples/api/test/widgets/framework/build_owner.0_test.dart',
377377
'examples/api/test/widgets/framework/error_widget.0_test.dart',
378378
'examples/api/test/widgets/inherited_theme/inherited_theme.0_test.dart',
379-
'examples/api/test/widgets/sliver/decorated_sliver.0_test.dart',
380379
'examples/api/test/widgets/autofill/autofill_group.0_test.dart',
381380
'examples/api/test/widgets/nested_scroll_view/nested_scroll_view_state.0_test.dart',
382381
'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart',

examples/api/lib/widgets/sliver/decorated_sliver.0.dart

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ class SliverDecorationExampleApp extends StatelessWidget {
1212
@override
1313
Widget build(BuildContext context) {
1414
return MaterialApp(
15+
theme: ThemeData(
16+
textTheme: const TextTheme(
17+
titleLarge: TextStyle(
18+
fontSize: 24,
19+
color: Colors.white30,
20+
),
21+
),
22+
),
1523
home: Scaffold(
1624
appBar: AppBar(title: const Text('SliverDecoration Sample')),
1725
body: const SliverDecorationExample(),
@@ -28,6 +36,7 @@ class SliverDecorationExample extends StatelessWidget {
2836
return CustomScrollView(
2937
slivers: <Widget>[
3038
DecoratedSliver(
39+
key: const ValueKey<String>('radial-gradient'),
3140
decoration: const BoxDecoration(
3241
gradient: RadialGradient(
3342
center: Alignment(-0.5, -0.6),
@@ -36,21 +45,60 @@ class SliverDecorationExample extends StatelessWidget {
3645
Color(0xFFEEEEEE),
3746
Color(0xFF111133),
3847
],
39-
stops: <double>[0.9, 1.0],
48+
stops: <double>[0.4, 0.8],
4049
),
4150
),
4251
sliver: SliverList(
43-
delegate: SliverChildListDelegate(<Widget>[
44-
const Text('Goodnight Moon'),
45-
]),
52+
delegate: SliverChildListDelegate(
53+
<Widget>[
54+
SizedBox(
55+
height: 200.0,
56+
child: Center(
57+
child: Text(
58+
'A moon on a night sky',
59+
style: Theme.of(context).textTheme.titleLarge,
60+
),
61+
),
62+
),
63+
],
64+
),
4665
),
4766
),
48-
const DecoratedSliver(
49-
decoration: BoxDecoration(
50-
color: Colors.amber,
51-
borderRadius: BorderRadius.all(Radius.circular(50))
67+
DecoratedSliver(
68+
key: const ValueKey<String>('linear-gradient'),
69+
decoration: const BoxDecoration(
70+
gradient: LinearGradient(
71+
begin: Alignment.topCenter,
72+
end: Alignment.bottomCenter,
73+
colors: <Color>[
74+
Color(0xFF111133),
75+
Color(0xFF1A237E),
76+
Color(0xFF283593),
77+
Color(0xFF3949AB),
78+
Color(0xFF3F51B5),
79+
Color(0xFF1976D2),
80+
Color(0xFF1E88E5),
81+
Color(0xFF42A5F5),
82+
],
83+
),
84+
),
85+
sliver: SliverList(
86+
delegate: SliverChildListDelegate(
87+
<Widget>[
88+
SizedBox(
89+
height: 500.0,
90+
child: Container(
91+
alignment: Alignment.topCenter,
92+
padding: const EdgeInsets.only(top: 56.0),
93+
child: Text(
94+
'A blue sky',
95+
style: Theme.of(context).textTheme.titleLarge,
96+
),
97+
),
98+
),
99+
],
100+
),
52101
),
53-
sliver: SliverToBoxAdapter(child: SizedBox(height: 300)),
54102
),
55103
],
56104
);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/widgets/sliver/decorated_sliver.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Verify the texts are displayed', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.SliverDecorationExampleApp(),
13+
);
14+
15+
final Finder moonText = find.text('A moon on a night sky');
16+
expect(moonText, findsOneWidget);
17+
18+
final Finder blueSkyText = find.text('A blue sky');
19+
expect(blueSkyText, findsOneWidget);
20+
});
21+
22+
testWidgets('Verify the sliver with key `radial-gradient` has a RadialGradient', (WidgetTester tester) async {
23+
await tester.pumpWidget(
24+
const example.SliverDecorationExampleApp(),
25+
);
26+
27+
final DecoratedSliver radialDecoratedSliver = tester.widget<DecoratedSliver>(
28+
find.byKey(const ValueKey<String>('radial-gradient')),
29+
);
30+
expect(
31+
radialDecoratedSliver.decoration,
32+
const BoxDecoration(
33+
gradient: RadialGradient(
34+
center: Alignment(-0.5, -0.6),
35+
radius: 0.15,
36+
colors: <Color>[
37+
Color(0xFFEEEEEE),
38+
Color(0xFF111133),
39+
],
40+
stops: <double>[0.4, 0.8],
41+
),
42+
),
43+
);
44+
});
45+
46+
testWidgets('Verify that the sliver with key `linear-gradient` has a LinearGradient', (WidgetTester tester) async {
47+
await tester.pumpWidget(
48+
const example.SliverDecorationExampleApp(),
49+
);
50+
51+
final DecoratedSliver linearDecoratedSliver = tester.widget<DecoratedSliver>(
52+
find.byKey(const ValueKey<String>('linear-gradient')),
53+
);
54+
expect(
55+
linearDecoratedSliver.decoration,
56+
const BoxDecoration(
57+
gradient: LinearGradient(
58+
begin: Alignment.topCenter,
59+
end: Alignment.bottomCenter,
60+
colors: <Color>[
61+
Color(0xFF111133),
62+
Color(0xFF1A237E),
63+
Color(0xFF283593),
64+
Color(0xFF3949AB),
65+
Color(0xFF3F51B5),
66+
Color(0xFF1976D2),
67+
Color(0xFF1E88E5),
68+
Color(0xFF42A5F5),
69+
],
70+
),
71+
),
72+
);
73+
});
74+
}

0 commit comments

Comments
 (0)