DecoratedSliver (#127823)
This is a second attempt to merge #107269. Currently I've fixed two of the issues: 1. Fixed horizontal scrollview by using a switch statement to consider vertical/horizontal case. 2. Fixed issue of `paintExtent` not being the right extent for painting. Rather using a `scrollExtent` for the main axis length of the decoration box and painting it offsetted by the `scrollOffset`. 3. If the sliver child has inifinite scrollExtent, then we only draw the decoration down to the bottom of the `cacheExtent`. The developer is expected to ensure that the border does not creep up above the cache area. This PR includes a test that checks that the correct rectangle is drawn at a certain scrollOffset for both the horizontal and vertical case which should be sufficient for checking that `SliverDecoration` works properly now. Fixes https://github.com/flutter/flutter/issues/107498.
This commit is contained in:
58
examples/api/lib/widgets/sliver/decorated_sliver.0.dart
Normal file
58
examples/api/lib/widgets/sliver/decorated_sliver.0.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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';
|
||||
|
||||
void main() => runApp(const SliverDecorationExampleApp());
|
||||
|
||||
class SliverDecorationExampleApp extends StatelessWidget {
|
||||
const SliverDecorationExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('SliverDecoration Sample')),
|
||||
body: const SliverDecorationExample(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SliverDecorationExample extends StatelessWidget {
|
||||
const SliverDecorationExample({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
DecoratedSliver(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: RadialGradient(
|
||||
center: Alignment(-0.5, -0.6),
|
||||
radius: 0.15,
|
||||
colors: <Color>[
|
||||
Color(0xFFEEEEEE),
|
||||
Color(0xFF111133),
|
||||
],
|
||||
stops: <double>[0.9, 1.0],
|
||||
),
|
||||
),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate(<Widget>[
|
||||
const Text('Goodnight Moon'),
|
||||
]),
|
||||
),
|
||||
),
|
||||
const DecoratedSliver(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.amber,
|
||||
borderRadius: BorderRadius.all(Radius.circular(50))
|
||||
),
|
||||
sliver: SliverToBoxAdapter(child: SizedBox(height: 300)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user