Optimize Overlay sample to avoid overflow (#155861)

Fixes [Optimize official `Overlay` sample to avoid overflowing.](https://github.com/flutter/flutter/issues/155860)

When checking https://main-api.flutter.dev/flutter/widgets/Overlay-class.html on a laptop screen it overflows as the layout uses Row instead of more robust widget for spacing `Wrap`

Quick Friday night fix. :) 

| Before | After |
| --------------- | --------------- |
| <img src="https://github.com/user-attachments/assets/eea6f1d9-e860-4ebd-8d16-2d8f4141e1ec" /> | <img src="https://github.com/user-attachments/assets/9f8426ba-d541-44a6-8ea6-2e34636b7e82"  /> |
This commit is contained in:
Taha Tesser 2024-09-28 12:20:32 +03:00 committed by GitHub
parent 71fd800e7e
commit 9f88de930b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 75 additions and 55 deletions

View File

@ -141,16 +141,22 @@ class _OverlayExampleState extends State<OverlayExample> {
),
],
),
body: Column(
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
spacing: 10.0,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Use Overlay to highlight a NavigationBar destination',
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
Wrap(
spacing: 10.0,
runSpacing: 10.0,
alignment: WrapAlignment.center,
runAlignment: WrapAlignment.center,
children: <Widget>[
// This creates a highlight Overlay for
// the Explore item.
@ -166,7 +172,6 @@ class _OverlayExampleState extends State<OverlayExample> {
},
child: const Text('Explore'),
),
const SizedBox(width: 20.0),
// This creates a highlight Overlay for
// the Commute item.
ElevatedButton(
@ -181,7 +186,6 @@ class _OverlayExampleState extends State<OverlayExample> {
},
child: const Text('Commute'),
),
const SizedBox(width: 20.0),
// This creates a highlight Overlay for
// the Saved item.
ElevatedButton(
@ -198,7 +202,6 @@ class _OverlayExampleState extends State<OverlayExample> {
),
],
),
const SizedBox(height: 10.0),
ElevatedButton(
onPressed: () {
removeHighlightOverlay();
@ -207,6 +210,8 @@ class _OverlayExampleState extends State<OverlayExample> {
),
],
),
),
),
);
}
}

View File

@ -38,4 +38,19 @@ void main() {
expect(find.text(commutePage), findsNothing);
expect(find.text(savedPage), findsNothing);
});
testWidgets('Narrow layout does not overflow', (WidgetTester tester) async {
// Set a narrow screen size.
tester.view
..physicalSize = const Size(320, 480)
..devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
const example.OverlayApp(),
);
// Verify that no overflow errors occur.
expect(tester.takeException(), isNull);
});
}