Skip to content

Commit 1857532

Browse files
authored
Revert "fix a Scaffold extendBodyBehindAppBar update bug" (#106396)
1 parent bf126b3 commit 1857532

File tree

4 files changed

+45
-70
lines changed

4 files changed

+45
-70
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ class _BodyBuilder extends StatelessWidget {
875875

876876
@override
877877
Widget build(BuildContext context) {
878+
if (!extendBody && !extendBodyBehindAppBar) {
879+
return body;
880+
}
881+
878882
return LayoutBuilder(
879883
builder: (BuildContext context, BoxConstraints constraints) {
880884
final _BodyBoxConstraints bodyConstraints = constraints as _BodyBoxConstraints;

packages/flutter/test/material/scaffold_test.dart

-35
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,6 @@ import 'package:flutter_test/flutter_test.dart';
1111
import '../widgets/semantics_tester.dart';
1212

1313
void main() {
14-
// Regression test for https://github.com/flutter/flutter/issues/103741
15-
testWidgets('extendBodyBehindAppBar change should not cause the body widget lose state', (WidgetTester tester) async {
16-
final ScrollController controller = ScrollController();
17-
Widget buildFrame({required bool extendBodyBehindAppBar}) {
18-
return MediaQuery(
19-
data: const MediaQueryData(),
20-
child: Directionality(
21-
textDirection: TextDirection.ltr,
22-
child: Scaffold(
23-
extendBodyBehindAppBar: extendBodyBehindAppBar,
24-
resizeToAvoidBottomInset: false,
25-
body: SingleChildScrollView(
26-
controller: controller,
27-
child: const FlutterLogo(
28-
size: 1107,
29-
),
30-
),
31-
),
32-
),
33-
);
34-
}
35-
36-
await tester.pumpWidget(buildFrame(extendBodyBehindAppBar: true));
37-
expect(controller.position.pixels, 0.0);
38-
39-
controller.jumpTo(100.0);
40-
await tester.pump();
41-
expect(controller.position.pixels, 100.0);
42-
43-
await tester.pumpWidget(buildFrame(extendBodyBehindAppBar: false));
44-
expect(controller.position.pixels, 100.0);
45-
});
46-
4714
testWidgets('Scaffold drawer callback test', (WidgetTester tester) async {
4815
bool isDrawerOpen = false;
4916
bool isEndDrawerOpen = false;
@@ -2434,8 +2401,6 @@ void main() {
24342401
' ancestor was:\n'
24352402
' Builder\n'
24362403
' The ancestors of this widget were:\n'
2437-
' MediaQuery\n'
2438-
' LayoutBuilder\n'
24392404
' _BodyBuilder\n'
24402405
' MediaQuery\n'
24412406
' LayoutId-[<_ScaffoldSlot.body>]\n'

packages/flutter/test/widgets/interactive_viewer_test.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,11 @@ void main() {
12691269
testWidgets('LayoutBuilder is only used for InteractiveViewer.builder', (WidgetTester tester) async {
12701270
await tester.pumpWidget(
12711271
MaterialApp(
1272-
home: Center(
1273-
child: InteractiveViewer(
1274-
child: const SizedBox(width: 200.0, height: 200.0),
1272+
home: Scaffold(
1273+
body: Center(
1274+
child: InteractiveViewer(
1275+
child: const SizedBox(width: 200.0, height: 200.0),
1276+
),
12751277
),
12761278
),
12771279
),
@@ -1281,11 +1283,13 @@ void main() {
12811283

12821284
await tester.pumpWidget(
12831285
MaterialApp(
1284-
home: Center(
1285-
child: InteractiveViewer.builder(
1286-
builder: (BuildContext context, Quad viewport) {
1287-
return const SizedBox(width: 200.0, height: 200.0);
1288-
},
1286+
home: Scaffold(
1287+
body: Center(
1288+
child: InteractiveViewer.builder(
1289+
builder: (BuildContext context, Quad viewport) {
1290+
return const SizedBox(width: 200.0, height: 200.0);
1291+
},
1292+
),
12891293
),
12901294
),
12911295
),

packages/flutter/test/widgets/nested_scroll_view_test.dart

+29-27
Original file line numberDiff line numberDiff line change
@@ -2360,35 +2360,37 @@ void main() {
23602360
testWidgets('NestedScrollView works well when rebuilding during scheduleWarmUpFrame', (WidgetTester tester) async {
23612361
bool? isScrolled;
23622362
final Widget myApp = MaterialApp(
2363-
home: StatefulBuilder(
2364-
builder: (BuildContext context, StateSetter setState) {
2365-
return Focus(
2366-
onFocusChange: (_) => setState( (){} ),
2367-
child: NestedScrollView(
2368-
headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
2369-
isScrolled = boxIsScrolled;
2370-
return <Widget>[
2371-
const SliverAppBar(
2372-
expandedHeight: 200,
2373-
title: Text('Test'),
2374-
),
2375-
];
2376-
},
2377-
body: CustomScrollView(
2378-
slivers: <Widget>[
2379-
SliverList(
2380-
delegate: SliverChildBuilderDelegate(
2381-
(BuildContext context, int index) {
2382-
return const Text('');
2383-
},
2384-
childCount: 10,
2363+
home: Scaffold(
2364+
body: StatefulBuilder(
2365+
builder: (BuildContext context, StateSetter setState) {
2366+
return Focus(
2367+
onFocusChange: (_) => setState( (){} ),
2368+
child: NestedScrollView(
2369+
headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
2370+
isScrolled = boxIsScrolled;
2371+
return <Widget>[
2372+
const SliverAppBar(
2373+
expandedHeight: 200,
2374+
title: Text('Test'),
23852375
),
2386-
),
2387-
],
2376+
];
2377+
},
2378+
body: CustomScrollView(
2379+
slivers: <Widget>[
2380+
SliverList(
2381+
delegate: SliverChildBuilderDelegate(
2382+
(BuildContext context, int index) {
2383+
return const Text('');
2384+
},
2385+
childCount: 10,
2386+
),
2387+
),
2388+
],
2389+
),
23882390
),
2389-
),
2390-
);
2391-
},
2391+
);
2392+
},
2393+
),
23922394
),
23932395
);
23942396

0 commit comments

Comments
 (0)