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 https://github.com/flutter/flutter/issues/145935
- Add test for `examples/api/test/widgets/sliver/decorated_sliver.0_test.dart` as a part of https://github.com/flutter/flutter/issues/130459.
This commit is contained in:
huycozy
2024-05-23 15:52:15 +07:00
committed by GitHub
parent abad37204e
commit e467289fb8
3 changed files with 131 additions and 10 deletions

View File

@@ -12,6 +12,14 @@ class SliverDecorationExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
textTheme: const TextTheme(
titleLarge: TextStyle(
fontSize: 24,
color: Colors.white30,
),
),
),
home: Scaffold(
appBar: AppBar(title: const Text('SliverDecoration Sample')),
body: const SliverDecorationExample(),
@@ -28,6 +36,7 @@ class SliverDecorationExample extends StatelessWidget {
return CustomScrollView(
slivers: <Widget>[
DecoratedSliver(
key: const ValueKey<String>('radial-gradient'),
decoration: const BoxDecoration(
gradient: RadialGradient(
center: Alignment(-0.5, -0.6),
@@ -36,21 +45,60 @@ class SliverDecorationExample extends StatelessWidget {
Color(0xFFEEEEEE),
Color(0xFF111133),
],
stops: <double>[0.9, 1.0],
stops: <double>[0.4, 0.8],
),
),
sliver: SliverList(
delegate: SliverChildListDelegate(<Widget>[
const Text('Goodnight Moon'),
]),
delegate: SliverChildListDelegate(
<Widget>[
SizedBox(
height: 200.0,
child: Center(
child: Text(
'A moon on a night sky',
style: Theme.of(context).textTheme.titleLarge,
),
),
),
],
),
),
),
const DecoratedSliver(
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.all(Radius.circular(50))
DecoratedSliver(
key: const ValueKey<String>('linear-gradient'),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[
Color(0xFF111133),
Color(0xFF1A237E),
Color(0xFF283593),
Color(0xFF3949AB),
Color(0xFF3F51B5),
Color(0xFF1976D2),
Color(0xFF1E88E5),
Color(0xFF42A5F5),
],
),
),
sliver: SliverList(
delegate: SliverChildListDelegate(
<Widget>[
SizedBox(
height: 500.0,
child: Container(
alignment: Alignment.topCenter,
padding: const EdgeInsets.only(top: 56.0),
child: Text(
'A blue sky',
style: Theme.of(context).textTheme.titleLarge,
),
),
),
],
),
),
sliver: SliverToBoxAdapter(child: SizedBox(height: 300)),
),
],
);