mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix the flexible space bar to still create a rendering object even if… (#62690)
This commit is contained in:
parent
6ab558d86a
commit
3af97d228c
@ -303,42 +303,42 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
||||
const double fadeEnd = 1.0;
|
||||
assert(fadeStart <= fadeEnd);
|
||||
final double opacity = 1.0 - Interval(fadeStart, fadeEnd).transform(t);
|
||||
if (opacity > 0.0) {
|
||||
double height = settings.maxExtent;
|
||||
double height = settings.maxExtent;
|
||||
|
||||
// StretchMode.zoomBackground
|
||||
if (widget.stretchModes.contains(StretchMode.zoomBackground) &&
|
||||
constraints.maxHeight > height) {
|
||||
height = constraints.maxHeight;
|
||||
}
|
||||
// StretchMode.zoomBackground
|
||||
if (widget.stretchModes.contains(StretchMode.zoomBackground) &&
|
||||
constraints.maxHeight > height) {
|
||||
height = constraints.maxHeight;
|
||||
}
|
||||
children.add(Positioned(
|
||||
top: _getCollapsePadding(t, settings),
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
height: height,
|
||||
child: Opacity(
|
||||
// IOS is relying on this semantics node to correctly traverse
|
||||
// through the app bar when it is collapsed.
|
||||
alwaysIncludeSemantics: true,
|
||||
opacity: opacity,
|
||||
child: widget.background,
|
||||
),
|
||||
));
|
||||
|
||||
children.add(Positioned(
|
||||
top: _getCollapsePadding(t, settings),
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
height: height,
|
||||
child: Opacity(
|
||||
opacity: opacity,
|
||||
child: widget.background,
|
||||
),
|
||||
));
|
||||
|
||||
// StretchMode.blurBackground
|
||||
if (widget.stretchModes.contains(StretchMode.blurBackground) &&
|
||||
constraints.maxHeight > settings.maxExtent) {
|
||||
final double blurAmount = (constraints.maxHeight - settings.maxExtent) / 10;
|
||||
children.add(Positioned.fill(
|
||||
child: BackdropFilter(
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
filter: ui.ImageFilter.blur(
|
||||
sigmaX: blurAmount,
|
||||
sigmaY: blurAmount,
|
||||
)
|
||||
// StretchMode.blurBackground
|
||||
if (widget.stretchModes.contains(StretchMode.blurBackground) &&
|
||||
constraints.maxHeight > settings.maxExtent) {
|
||||
final double blurAmount = (constraints.maxHeight - settings.maxExtent) / 10;
|
||||
children.add(Positioned.fill(
|
||||
child: BackdropFilter(
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
filter: ui.ImageFilter.blur(
|
||||
sigmaX: blurAmount,
|
||||
sigmaY: blurAmount,
|
||||
)
|
||||
));
|
||||
}
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FlexibleSpaceBar centers title on iOS', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
@ -119,6 +121,248 @@ void main() {
|
||||
expect(clipRect.size.height, minExtent);
|
||||
});
|
||||
|
||||
testWidgets('Collpased FlexibleSpaceBar has correct semantics', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
const double expandedHeight = 200;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
const SliverAppBar(
|
||||
pinned: true,
|
||||
expandedHeight: expandedHeight,
|
||||
title: Text('Title'),
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Text('Expanded title'),
|
||||
),
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
<Widget>[
|
||||
for (int i = 0; i < 50; i++)
|
||||
Container(
|
||||
height: 200,
|
||||
child: Center(child: Text('Item $i')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
TestSemantics expectedSemantics = TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
TestSemantics.rootChild(
|
||||
id: 1,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 2,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 3,
|
||||
rect: TestSemantics.fullScreen,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 4,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 9,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight),
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 11,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0),
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isHeader,
|
||||
SemanticsFlag.namesRoute
|
||||
],
|
||||
label: 'Title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 10,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, expandedHeight),
|
||||
label: 'Expanded title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
],
|
||||
),
|
||||
TestSemantics(
|
||||
id: 12,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||
rect: TestSemantics.fullScreen,
|
||||
actions: <SemanticsAction>[SemanticsAction.scrollUp],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 5,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
label: 'Item 0',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 6,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
label: 'Item 1',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 7,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 2',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 8,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 3',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true));
|
||||
|
||||
// We drag up to fully collapse the space bar.
|
||||
await tester.drag(find.text('Item 1'), const Offset(0, -600.0));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expectedSemantics = TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
TestSemantics.rootChild(
|
||||
id: 1,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 2,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 3,
|
||||
rect: TestSemantics.fullScreen,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 4,
|
||||
rect: TestSemantics.fullScreen,
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 9,
|
||||
// The app bar is collapsed.
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 56.0),
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 11,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 20.0),
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isHeader,
|
||||
SemanticsFlag.namesRoute
|
||||
],
|
||||
label: 'Title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
// The flexible space bar still persists in the
|
||||
// semantic tree even if it is collapsed.
|
||||
TestSemantics(
|
||||
id: 10,
|
||||
rect: const Rect.fromLTRB(0.0, 36.0, 800.0, 92.0),
|
||||
label: 'Expanded title',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
],
|
||||
),
|
||||
TestSemantics(
|
||||
id: 12,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||
rect: TestSemantics.fullScreen,
|
||||
actions: <SemanticsAction>[SemanticsAction.scrollUp, SemanticsAction.scrollDown],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 5,
|
||||
rect: const Rect.fromLTRB(0.0, 150.0, 800.0, 200.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 0',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 6,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 1',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 7,
|
||||
rect: const Rect.fromLTRB(0.0, 56.0, 800.0, 200.0),
|
||||
label: 'Item 2',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 8,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
label: 'Item 3',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 13,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
label: 'Item 4',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 14,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 5',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
TestSemantics(
|
||||
id: 15,
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0),
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||
label: 'Item 6',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
// This is a regression test for https://github.com/flutter/flutter/issues/14227
|
||||
testWidgets('FlexibleSpaceBar sets width constraints for the title', (WidgetTester tester) async {
|
||||
const double titleFontSize = 20.0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user