mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
SliverAppBar shape property (#33073)
This commit is contained in:
parent
277d5fe5f6
commit
3265e15925
@ -687,6 +687,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
||||
@required this.floating,
|
||||
@required this.pinned,
|
||||
@required this.snapConfiguration,
|
||||
@required this.shape,
|
||||
}) : assert(primary || topPadding == 0.0),
|
||||
_bottomHeight = bottom?.preferredSize?.height ?? 0.0;
|
||||
|
||||
@ -711,6 +712,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
||||
final double topPadding;
|
||||
final bool floating;
|
||||
final bool pinned;
|
||||
final ShapeBorder shape;
|
||||
|
||||
final double _bottomHeight;
|
||||
|
||||
@ -765,6 +767,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
||||
primary: primary,
|
||||
centerTitle: centerTitle,
|
||||
titleSpacing: titleSpacing,
|
||||
shape: shape,
|
||||
toolbarOpacity: toolbarOpacity,
|
||||
bottomOpacity: pinned ? 1.0 : (visibleMainHeight / _bottomHeight).clamp(0.0, 1.0),
|
||||
),
|
||||
@ -908,6 +911,7 @@ class SliverAppBar extends StatefulWidget {
|
||||
this.floating = false,
|
||||
this.pinned = false,
|
||||
this.snap = false,
|
||||
this.shape,
|
||||
}) : assert(automaticallyImplyLeading != null),
|
||||
assert(forceElevated != null),
|
||||
assert(primary != null),
|
||||
@ -1125,6 +1129,12 @@ class SliverAppBar extends StatefulWidget {
|
||||
/// behavior of the app bar in combination with [floating].
|
||||
final bool pinned;
|
||||
|
||||
/// The material's shape as well its shadow.
|
||||
///
|
||||
/// A shadow is only displayed if the [elevation] is greater than
|
||||
/// zero.
|
||||
final ShapeBorder shape;
|
||||
|
||||
/// If [snap] and [floating] are true then the floating app bar will "snap"
|
||||
/// into view.
|
||||
///
|
||||
@ -1221,6 +1231,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
|
||||
topPadding: topPadding,
|
||||
floating: widget.floating,
|
||||
pinned: widget.pinned,
|
||||
shape: widget.shape,
|
||||
snapConfiguration: _snapConfiguration,
|
||||
),
|
||||
),
|
||||
|
||||
@ -1425,7 +1425,6 @@ void main() {
|
||||
|
||||
testWidgets('Changing SliverAppBar snap from true to false', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/17598
|
||||
|
||||
const double appBarHeight = 256.0;
|
||||
bool snap = true;
|
||||
|
||||
@ -1486,32 +1485,99 @@ void main() {
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('AppBar with shape', (WidgetTester tester) async {
|
||||
const RoundedRectangleBorder roundedRectangleBorder = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(15.0)));
|
||||
testWidgets('AppBar shape default', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AppBar(
|
||||
leading: const Text('L'),
|
||||
title: const Text('No Scaffold'),
|
||||
shape: roundedRectangleBorder,
|
||||
actions: const <Widget>[Text('A1'), Text('A2')],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder appBarFinder = find.byType(AppBar);
|
||||
|
||||
AppBar getAppBarWidget() {
|
||||
return tester.widget<AppBar>(appBarFinder);
|
||||
}
|
||||
|
||||
expect(getAppBarWidget().shape, roundedRectangleBorder);
|
||||
AppBar getAppBarWidget(Finder finder) => tester.widget<AppBar>(finder);
|
||||
expect(getAppBarWidget(appBarFinder).shape, null);
|
||||
|
||||
final Finder materialFinder = find.byType(Material);
|
||||
Material getMaterialWidget() {
|
||||
return tester.widget<Material>(materialFinder);
|
||||
}
|
||||
Material getMaterialWidget(Finder finder) => tester.widget<Material>(finder);
|
||||
expect(getMaterialWidget(materialFinder).shape, null);
|
||||
});
|
||||
|
||||
expect(getMaterialWidget().shape, roundedRectangleBorder);
|
||||
testWidgets('AppBar with shape', (WidgetTester tester) async {
|
||||
const RoundedRectangleBorder roundedRectangleBorder = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(15.0))
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AppBar(
|
||||
leading: const Text('L'),
|
||||
title: const Text('No Scaffold'),
|
||||
actions: const <Widget>[Text('A1'), Text('A2')],
|
||||
shape: roundedRectangleBorder,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder appBarFinder = find.byType(AppBar);
|
||||
AppBar getAppBarWidget(Finder finder) => tester.widget<AppBar>(finder);
|
||||
expect(getAppBarWidget(appBarFinder).shape, roundedRectangleBorder);
|
||||
|
||||
final Finder materialFinder = find.byType(Material);
|
||||
Material getMaterialWidget(Finder finder) => tester.widget<Material>(finder);
|
||||
expect(getMaterialWidget(materialFinder).shape, roundedRectangleBorder);
|
||||
});
|
||||
|
||||
testWidgets('SliverAppBar shape default', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverAppBar(
|
||||
leading: Text('L'),
|
||||
title: Text('No Scaffold'),
|
||||
actions: <Widget>[Text('A1'), Text('A2')],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder sliverAppBarFinder = find.byType(SliverAppBar);
|
||||
SliverAppBar getSliverAppBarWidget(Finder finder) => tester.widget<SliverAppBar>(finder);
|
||||
expect(getSliverAppBarWidget(sliverAppBarFinder).shape, null);
|
||||
|
||||
final Finder materialFinder = find.byType(Material);
|
||||
Material getMaterialWidget(Finder finder) => tester.widget<Material>(finder);
|
||||
expect(getMaterialWidget(materialFinder).shape, null);
|
||||
});
|
||||
|
||||
testWidgets('SliverAppBar with shape', (WidgetTester tester) async {
|
||||
const RoundedRectangleBorder roundedRectangleBorder = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(15.0)),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverAppBar(
|
||||
leading: Text('L'),
|
||||
title: Text('No Scaffold'),
|
||||
actions: <Widget>[Text('A1'), Text('A2')],
|
||||
shape: roundedRectangleBorder,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder sliverAppBarFinder = find.byType(SliverAppBar);
|
||||
SliverAppBar getSliverAppBarWidget(Finder finder) => tester.widget<SliverAppBar>(finder);
|
||||
expect(getSliverAppBarWidget(sliverAppBarFinder).shape, roundedRectangleBorder);
|
||||
|
||||
final Finder materialFinder = find.byType(Material);
|
||||
Material getMaterialWidget(Finder finder) => tester.widget<Material>(finder);
|
||||
expect(getMaterialWidget(materialFinder).shape, roundedRectangleBorder);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user