Unverified Commit ea28f287 authored by xubaolin's avatar xubaolin Committed by GitHub

fix a Scaffold extendBodyBehindAppBar update bug (#104958)

parent 512e090d
......@@ -875,10 +875,6 @@ class _BodyBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (!extendBody && !extendBodyBehindAppBar) {
return body;
}
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final _BodyBoxConstraints bodyConstraints = constraints as _BodyBoxConstraints;
......
......@@ -11,6 +11,39 @@ import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart';
void main() {
// Regression test for https://github.com/flutter/flutter/issues/103741
testWidgets('extendBodyBehindAppBar change should not cause the body widget lose state', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
Widget buildFrame({required bool extendBodyBehindAppBar}) {
return MediaQuery(
data: const MediaQueryData(),
child: Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
extendBodyBehindAppBar: extendBodyBehindAppBar,
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
controller: controller,
child: const FlutterLogo(
size: 1107,
),
),
),
),
);
}
await tester.pumpWidget(buildFrame(extendBodyBehindAppBar: true));
expect(controller.position.pixels, 0.0);
controller.jumpTo(100.0);
await tester.pump();
expect(controller.position.pixels, 100.0);
await tester.pumpWidget(buildFrame(extendBodyBehindAppBar: false));
expect(controller.position.pixels, 100.0);
});
testWidgets('Scaffold drawer callback test', (WidgetTester tester) async {
bool isDrawerOpen = false;
bool isEndDrawerOpen = false;
......@@ -2401,6 +2434,8 @@ void main() {
' ancestor was:\n'
' Builder\n'
' The ancestors of this widget were:\n'
' MediaQuery\n'
' LayoutBuilder\n'
' _BodyBuilder\n'
' MediaQuery\n'
' LayoutId-[<_ScaffoldSlot.body>]\n'
......
......@@ -1269,22 +1269,19 @@ void main() {
testWidgets('LayoutBuilder is only used for InteractiveViewer.builder', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
home: Center(
child: InteractiveViewer(
child: const SizedBox(width: 200.0, height: 200.0),
),
),
),
),
);
expect(find.byType(LayoutBuilder), findsNothing);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
home: Center(
child: InteractiveViewer.builder(
builder: (BuildContext context, Quad viewport) {
return const SizedBox(width: 200.0, height: 200.0);
......@@ -1292,7 +1289,6 @@ void main() {
),
),
),
),
);
expect(find.byType(LayoutBuilder), findsOneWidget);
......
......@@ -2360,8 +2360,7 @@ void main() {
testWidgets('NestedScrollView works well when rebuilding during scheduleWarmUpFrame', (WidgetTester tester) async {
bool? isScrolled;
final Widget myApp = MaterialApp(
home: Scaffold(
body: StatefulBuilder(
home: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Focus(
onFocusChange: (_) => setState( (){} ),
......@@ -2391,7 +2390,6 @@ void main() {
);
},
),
),
);
await tester.pumpWidget(myApp, Duration.zero, EnginePhase.build);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment