Skip to content

Commit 0a88d82

Browse files
authored
fix a _ScaffoldLayout delegate update bug (#104954)
1 parent 80bfc8f commit 0a88d82

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

packages/flutter/lib/src/material/scaffold.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,12 +1144,13 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
11441144
@override
11451145
bool shouldRelayout(_ScaffoldLayout oldDelegate) {
11461146
return oldDelegate.minInsets != minInsets
1147-
|| oldDelegate.textDirection != textDirection
1148-
|| oldDelegate.floatingActionButtonMoveAnimationProgress != floatingActionButtonMoveAnimationProgress
1149-
|| oldDelegate.previousFloatingActionButtonLocation != previousFloatingActionButtonLocation
1150-
|| oldDelegate.currentFloatingActionButtonLocation != currentFloatingActionButtonLocation
1151-
|| oldDelegate.extendBody != extendBody
1152-
|| oldDelegate.extendBodyBehindAppBar != extendBodyBehindAppBar;
1147+
|| oldDelegate.minViewPadding != minViewPadding
1148+
|| oldDelegate.textDirection != textDirection
1149+
|| oldDelegate.floatingActionButtonMoveAnimationProgress != floatingActionButtonMoveAnimationProgress
1150+
|| oldDelegate.previousFloatingActionButtonLocation != previousFloatingActionButtonLocation
1151+
|| oldDelegate.currentFloatingActionButtonLocation != currentFloatingActionButtonLocation
1152+
|| oldDelegate.extendBody != extendBody
1153+
|| oldDelegate.extendBodyBehindAppBar != extendBodyBehindAppBar;
11531154
}
11541155
}
11551156

@@ -2861,7 +2862,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
28612862
// The minimum viewPadding for interactive elements positioned by the
28622863
// Scaffold to keep within safe interactive areas.
28632864
final EdgeInsets minViewPadding = mediaQuery.viewPadding.copyWith(
2864-
bottom: _resizeToAvoidBottomInset && mediaQuery.viewInsets.bottom != 0.0 ? 0.0 : null,
2865+
bottom: _resizeToAvoidBottomInset && mediaQuery.viewInsets.bottom != 0.0 ? 0.0 : null,
28652866
);
28662867

28672868
// extendBody locked when keyboard is open

packages/flutter/test/material/scaffold_test.dart

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,17 @@ void main() {
276276
await tester.pumpWidget(
277277
MediaQuery(
278278
data: const MediaQueryData(
279-
padding: EdgeInsets.only(bottom: 20.0),
279+
viewPadding: EdgeInsets.only(bottom: 20.0),
280280
),
281281
child: child,
282282
),
283283
);
284284
final Offset initialPoint = tester.getCenter(find.byType(Placeholder));
285+
expect(
286+
tester.getBottomLeft(find.byType(Placeholder)).dy,
287+
moreOrLessEquals(600.0 - 20.0 - kFloatingActionButtonMargin)
288+
);
289+
285290
// Consume bottom padding - as if by the keyboard opening
286291
await tester.pumpWidget(
287292
MediaQuery(
@@ -296,6 +301,37 @@ void main() {
296301
expect(initialPoint, finalPoint);
297302
});
298303

304+
testWidgets('viewPadding change should trigger _ScaffoldLayout re-layout', (WidgetTester tester) async {
305+
Widget buildFrame(EdgeInsets viewPadding) {
306+
return MediaQuery(
307+
data: MediaQueryData(
308+
viewPadding: viewPadding,
309+
),
310+
child: Directionality(
311+
textDirection: TextDirection.ltr,
312+
child: Scaffold(
313+
resizeToAvoidBottomInset: false,
314+
body: Container(),
315+
floatingActionButton: const Placeholder(),
316+
),
317+
),
318+
);
319+
}
320+
321+
await tester.pumpWidget(buildFrame(const EdgeInsets.only(bottom: 300)));
322+
323+
final RenderBox renderBox = tester.renderObject<RenderBox>(find.byType(CustomMultiChildLayout));
324+
expect(renderBox.debugNeedsLayout, false);
325+
326+
await tester.pumpWidget(
327+
buildFrame(const EdgeInsets.only(bottom: 400)),
328+
null,
329+
EnginePhase.build,
330+
);
331+
332+
expect(renderBox.debugNeedsLayout, true);
333+
});
334+
299335
testWidgets('Drawer scrolling', (WidgetTester tester) async {
300336
final Key drawerKey = UniqueKey();
301337
const double appBarHeight = 256.0;

0 commit comments

Comments
 (0)