SliverAppBar Default Elevation Patch (#73526)
This commit is contained in:
parent
17c5c4c33a
commit
01b7ada7c1
@ -1154,7 +1154,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
? Semantics(child: flexibleSpace, header: true)
|
? Semantics(child: flexibleSpace, header: true)
|
||||||
: flexibleSpace,
|
: flexibleSpace,
|
||||||
bottom: bottom,
|
bottom: bottom,
|
||||||
elevation: forceElevated || overlapsContent || (pinned && shrinkOffset > maxExtent - minExtent) ? elevation ?? 4.0 : 0.0,
|
elevation: forceElevated || overlapsContent || (pinned && shrinkOffset > maxExtent - minExtent) ? elevation : 0.0,
|
||||||
shadowColor: shadowColor,
|
shadowColor: shadowColor,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
foregroundColor: foregroundColor,
|
foregroundColor: foregroundColor,
|
||||||
|
@ -903,30 +903,79 @@ void main() {
|
|||||||
expect(tabBarHeight(tester), initialTabBarHeight);
|
expect(tabBarHeight(tester), initialTabBarHeight);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('SliverAppBar rebuilds when forceElevated changes', (WidgetTester tester) async {
|
testWidgets('AppBar uses the specified elevation or defaults to 4.0', (WidgetTester tester) async {
|
||||||
// Regression test for https://github.com/flutter/flutter/issues/59158.
|
Widget buildAppBar([double? elevation]) {
|
||||||
Widget buildSliverAppBar(bool forceElevated) {
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Title'), elevation: elevation),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Material getMaterial() => tester.widget<Material>(find.descendant(
|
||||||
|
of: find.byType(AppBar),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Default elevation should be _AppBarState._defaultElevation = 4.0
|
||||||
|
await tester.pumpWidget(buildAppBar());
|
||||||
|
expect(getMaterial().elevation, 4.0);
|
||||||
|
|
||||||
|
// AppBar should use the specified elevation.
|
||||||
|
await tester.pumpWidget(buildAppBar(8.0));
|
||||||
|
expect(getMaterial().elevation, 8.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('SliverAppBar elevation', () {
|
||||||
|
Widget buildSliverAppBar(bool forceElevated, {double? elevation, double? themeElevation}) {
|
||||||
|
return MaterialApp(
|
||||||
|
theme: ThemeData(appBarTheme: AppBarTheme(elevation: themeElevation)),
|
||||||
home: CustomScrollView(
|
home: CustomScrollView(
|
||||||
slivers: <Widget>[
|
slivers: <Widget>[
|
||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
backwardsCompatibility: false,
|
backwardsCompatibility: false,
|
||||||
title: const Text('Title'),
|
title: const Text('Title'),
|
||||||
forceElevated: forceElevated,
|
forceElevated: forceElevated,
|
||||||
|
elevation: elevation,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Finder appBarFinder = find.byType(AppBar);
|
testWidgets('Respects forceElevated parameter', (WidgetTester tester) async {
|
||||||
AppBar getAppBarWidget(Finder finder) => tester.widget<AppBar>(finder);
|
// Regression test for https://github.com/flutter/flutter/issues/59158.
|
||||||
|
AppBar getAppBar() => tester.widget<AppBar>(find.byType(AppBar));
|
||||||
|
Material getMaterial() => tester.widget<Material>(find.byType(Material));
|
||||||
|
|
||||||
|
// When forceElevated is off, SliverAppBar should not be elevated.
|
||||||
await tester.pumpWidget(buildSliverAppBar(false));
|
await tester.pumpWidget(buildSliverAppBar(false));
|
||||||
expect(getAppBarWidget(appBarFinder).elevation, 0.0);
|
expect(getMaterial().elevation, 0.0);
|
||||||
|
|
||||||
|
// Default elevation should be _AppBarState._defaultElevation = 4.0, and
|
||||||
|
// the AppBar's elevation should not be specified by SliverAppBar.
|
||||||
await tester.pumpWidget(buildSliverAppBar(true));
|
await tester.pumpWidget(buildSliverAppBar(true));
|
||||||
expect(getAppBarWidget(appBarFinder).elevation, 4.0);
|
expect(getMaterial().elevation, 4.0);
|
||||||
|
expect(getAppBar().elevation, null);
|
||||||
|
|
||||||
|
// SliverAppBar should use the specified elevation.
|
||||||
|
await tester.pumpWidget(buildSliverAppBar(true, elevation: 8.0));
|
||||||
|
expect(getMaterial().elevation, 8.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Uses elevation of AppBarTheme by default', (WidgetTester tester) async {
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/73525.
|
||||||
|
Material getMaterial() => tester.widget<Material>(find.byType(Material));
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildSliverAppBar(false, themeElevation: 12.0));
|
||||||
|
expect(getMaterial().elevation, 0.0);
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildSliverAppBar(true, themeElevation: 12.0));
|
||||||
|
expect(getMaterial().elevation, 12.0);
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildSliverAppBar(true, elevation: 8.0, themeElevation: 12.0));
|
||||||
|
expect(getMaterial().elevation, 8.0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AppBar dimensions, with and without bottom, primary', (WidgetTester tester) async {
|
testWidgets('AppBar dimensions, with and without bottom, primary', (WidgetTester tester) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user