Skip to content

Commit dc58093

Browse files
Fix SafeArea DartPad sample (#159344)
This pull request fixes a bug I introduced in flutter/flutter#158019. <br> <h3 align="center">Before</h3> <p align="center"> <img src="https://github.com/user-attachments/assets/fcb68fac-9c63-445d-8d2b-afc28c685053" alt="RenderFlex overflowed" width="523px" /> </p> <h3 align="center">After</h3> <p align="center"> <img src="https://github.com/user-attachments/assets/82091c6a-b3c5-4994-978e-5e76cbb7edfd" alt="RenderFlex overflowed" width="523px" /> </p> <br><br> - fixes flutter/flutter#159340
1 parent f787135 commit dc58093

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

examples/api/lib/widgets/safe_area/safe_area.0.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SafeAreaExampleApp extends StatelessWidget {
2626
scaffoldBackgroundColor: const Color(0xFFD0FFE8),
2727
listTileTheme: const ListTileThemeData(
2828
tileColor: Colors.white70,
29-
contentPadding: EdgeInsets.all(6.0),
29+
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
3030
),
3131
appBarTheme: AppBarTheme(
3232
backgroundColor: colors.secondary,
@@ -65,7 +65,7 @@ class SafeAreaExample extends StatelessWidget {
6565

6666
static final Widget controls = Column(
6767
children: <Widget>[
68-
const SizedBox(height: 14),
68+
const SizedBox(height: 6),
6969
Builder(
7070
builder: (BuildContext context) => Text(
7171
Toggle.safeArea.of(context) ? 'safe area!' : 'no safe area',

examples/api/test/widgets/safe_area/safe_area.0_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,33 @@ void main() {
8181
context = tester.element(find.text('safe area!'));
8282
expect(MediaQuery.paddingOf(context), EdgeInsets.zero);
8383
});
84+
85+
// Regression test for https://github.com/flutter/flutter/issues/159340.
86+
testWidgets('App displays without layout issues', (WidgetTester tester) async {
87+
// Set the app's size to to match the default DartPad demo screen.
88+
await tester.pumpWidget(
89+
const Center(
90+
child: SizedBox(
91+
width: 500.0,
92+
height: 480.0,
93+
child: example.Insets(),
94+
),
95+
),
96+
);
97+
98+
double appScreenHeight() => tester.getRect(find.byType(example.Insets)).height;
99+
100+
expect(appScreenHeight(), 480);
101+
expect(insetsState.insets, const EdgeInsets.fromLTRB(8.0, 25.0, 8.0, 12.0));
102+
103+
// Drag each slider to its maximum value.
104+
for (int index = 0; index < 3; index++) {
105+
await tester.drag(find.byType(Slider).at(index), const Offset(500.0, 0.0));
106+
await tester.pumpAndSettle();
107+
expect(tester.takeException(), isNull);
108+
}
109+
110+
expect(appScreenHeight(), 480);
111+
expect(insetsState.insets, const EdgeInsets.all(50));
112+
});
84113
}

0 commit comments

Comments
 (0)