fix a _ScaffoldLayout delegate update bug (#104954)

This commit is contained in:
xubaolin
2022-06-08 06:08:09 +08:00
committed by GitHub
parent 80bfc8f35a
commit 0a88d820fd
2 changed files with 45 additions and 8 deletions

View File

@@ -1144,12 +1144,13 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
@override
bool shouldRelayout(_ScaffoldLayout oldDelegate) {
return oldDelegate.minInsets != minInsets
|| oldDelegate.textDirection != textDirection
|| oldDelegate.floatingActionButtonMoveAnimationProgress != floatingActionButtonMoveAnimationProgress
|| oldDelegate.previousFloatingActionButtonLocation != previousFloatingActionButtonLocation
|| oldDelegate.currentFloatingActionButtonLocation != currentFloatingActionButtonLocation
|| oldDelegate.extendBody != extendBody
|| oldDelegate.extendBodyBehindAppBar != extendBodyBehindAppBar;
|| oldDelegate.minViewPadding != minViewPadding
|| oldDelegate.textDirection != textDirection
|| oldDelegate.floatingActionButtonMoveAnimationProgress != floatingActionButtonMoveAnimationProgress
|| oldDelegate.previousFloatingActionButtonLocation != previousFloatingActionButtonLocation
|| oldDelegate.currentFloatingActionButtonLocation != currentFloatingActionButtonLocation
|| oldDelegate.extendBody != extendBody
|| oldDelegate.extendBodyBehindAppBar != extendBodyBehindAppBar;
}
}
@@ -2861,7 +2862,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
// The minimum viewPadding for interactive elements positioned by the
// Scaffold to keep within safe interactive areas.
final EdgeInsets minViewPadding = mediaQuery.viewPadding.copyWith(
bottom: _resizeToAvoidBottomInset && mediaQuery.viewInsets.bottom != 0.0 ? 0.0 : null,
bottom: _resizeToAvoidBottomInset && mediaQuery.viewInsets.bottom != 0.0 ? 0.0 : null,
);
// extendBody locked when keyboard is open

View File

@@ -276,12 +276,17 @@ void main() {
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.only(bottom: 20.0),
viewPadding: EdgeInsets.only(bottom: 20.0),
),
child: child,
),
);
final Offset initialPoint = tester.getCenter(find.byType(Placeholder));
expect(
tester.getBottomLeft(find.byType(Placeholder)).dy,
moreOrLessEquals(600.0 - 20.0 - kFloatingActionButtonMargin)
);
// Consume bottom padding - as if by the keyboard opening
await tester.pumpWidget(
MediaQuery(
@@ -296,6 +301,37 @@ void main() {
expect(initialPoint, finalPoint);
});
testWidgets('viewPadding change should trigger _ScaffoldLayout re-layout', (WidgetTester tester) async {
Widget buildFrame(EdgeInsets viewPadding) {
return MediaQuery(
data: MediaQueryData(
viewPadding: viewPadding,
),
child: Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Container(),
floatingActionButton: const Placeholder(),
),
),
);
}
await tester.pumpWidget(buildFrame(const EdgeInsets.only(bottom: 300)));
final RenderBox renderBox = tester.renderObject<RenderBox>(find.byType(CustomMultiChildLayout));
expect(renderBox.debugNeedsLayout, false);
await tester.pumpWidget(
buildFrame(const EdgeInsets.only(bottom: 400)),
null,
EnginePhase.build,
);
expect(renderBox.debugNeedsLayout, true);
});
testWidgets('Drawer scrolling', (WidgetTester tester) async {
final Key drawerKey = UniqueKey();
const double appBarHeight = 256.0;