Add shape property to SliverAppBar (#31662)

This commit is contained in:
Tiziano Munegato 2019-05-06 19:34:37 +02:00 committed by Shi-Hao Hong
parent 017997b9c1
commit 28b58db1f2
2 changed files with 46 additions and 0 deletions

View file

@ -681,6 +681,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
@required this.floating, @required this.floating,
@required this.pinned, @required this.pinned,
@required this.snapConfiguration, @required this.snapConfiguration,
@required this.shape,
}) : assert(primary || topPadding == 0.0), }) : assert(primary || topPadding == 0.0),
_bottomHeight = bottom?.preferredSize?.height ?? 0.0; _bottomHeight = bottom?.preferredSize?.height ?? 0.0;
@ -705,6 +706,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final double topPadding; final double topPadding;
final bool floating; final bool floating;
final bool pinned; final bool pinned;
final ShapeBorder shape;
final double _bottomHeight; final double _bottomHeight;
@ -759,6 +761,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
primary: primary, primary: primary,
centerTitle: centerTitle, centerTitle: centerTitle,
titleSpacing: titleSpacing, titleSpacing: titleSpacing,
shape: shape,
toolbarOpacity: toolbarOpacity, toolbarOpacity: toolbarOpacity,
bottomOpacity: pinned ? 1.0 : (visibleMainHeight / _bottomHeight).clamp(0.0, 1.0), bottomOpacity: pinned ? 1.0 : (visibleMainHeight / _bottomHeight).clamp(0.0, 1.0),
), ),
@ -902,6 +905,7 @@ class SliverAppBar extends StatefulWidget {
this.floating = false, this.floating = false,
this.pinned = false, this.pinned = false,
this.snap = false, this.snap = false,
this.shape,
}) : assert(automaticallyImplyLeading != null), }) : assert(automaticallyImplyLeading != null),
assert(forceElevated != null), assert(forceElevated != null),
assert(primary != null), assert(primary != null),
@ -1062,6 +1066,12 @@ class SliverAppBar extends StatefulWidget {
/// Defaults to [NavigationToolbar.kMiddleSpacing]. /// Defaults to [NavigationToolbar.kMiddleSpacing].
final double titleSpacing; final double titleSpacing;
/// The material's shape as well its shadow.
///
/// A shadow is only displayed if the [elevation] is greater than
/// zero.
final ShapeBorder shape;
/// The size of the app bar when it is fully expanded. /// The size of the app bar when it is fully expanded.
/// ///
/// By default, the total height of the toolbar and the bottom widget (if /// By default, the total height of the toolbar and the bottom widget (if
@ -1215,6 +1225,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
topPadding: topPadding, topPadding: topPadding,
floating: widget.floating, floating: widget.floating,
pinned: widget.pinned, pinned: widget.pinned,
shape: widget.shape,
snapConfiguration: _snapConfiguration, snapConfiguration: _snapConfiguration,
), ),
), ),

View file

@ -1514,4 +1514,39 @@ void main() {
expect(getMaterialWidget().shape, roundedRectangleBorder); expect(getMaterialWidget().shape, roundedRectangleBorder);
}); });
testWidgets('SliverAppBar with shape', (WidgetTester tester) async {
const RoundedRectangleBorder roundedRectangleBorder = RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
);
await tester.pumpWidget(
MaterialApp(
home: CustomScrollView(
slivers: const <Widget>[
SliverAppBar(
leading: Text('L'),
title: Text('No Scaffold'),
shape: roundedRectangleBorder,
actions: <Widget>[Text('A1'), Text('A2')],
),
],
),
),
);
final Finder sliverAppBarFinder = find.byType(SliverAppBar);
SliverAppBar getAppBarWidget() {
return tester.widget<SliverAppBar>(sliverAppBarFinder);
}
expect(getAppBarWidget().shape, roundedRectangleBorder);
final Finder materialFinder = find.byType(Material);
Material getMaterialWidget() {
return tester.widget<Material>(materialFinder);
}
expect(getMaterialWidget().shape, roundedRectangleBorder);
});
} }