Fixed RenderFlex overflow in RouteObserver Example (#170980)

Fixed RenderOverflow in RouteObserver Example:
https://api.flutter.dev/flutter/widgets/RouteObserver-class.html

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

This PR is about solving render overflow issue in Route Observer Example
in Live Website. I've wrapped the body with a Scrollable View to solve
this issue

| | |
| --- | --- |
| B |
![image](https://github.com/user-attachments/assets/c8fa78e7-62ca-4bd1-9798-588c636cd61a)
|
| A |
![image](https://github.com/user-attachments/assets/3a2b4697-121a-43e3-9c85-b1379a575af1)
|

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.


<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
Pacific 2025-12-11 02:23:33 +05:30 committed by GitHub
parent f8b88be694
commit 2c4e7ebfd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 30 deletions

View File

@ -63,37 +63,39 @@ class _RouteObserverExampleState extends State<RouteObserverExample>
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'RouteObserver log:',
style: Theme.of(context).textTheme.headlineSmall,
),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 300.0),
child: ListView.builder(
itemCount: log.length,
itemBuilder: (BuildContext context, int index) {
if (log.isEmpty) {
return const SizedBox.shrink();
}
return Text(log[index], textAlign: TextAlign.center);
},
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'RouteObserver log:',
style: Theme.of(context).textTheme.headlineSmall,
),
),
OutlinedButton(
onPressed: () {
Navigator.of(context).push<void>(
MaterialPageRoute<void>(
builder: (BuildContext context) => const NextPage(),
),
);
},
child: const Text('Go to next page'),
),
],
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 300.0),
child: ListView.builder(
itemCount: log.length,
itemBuilder: (BuildContext context, int index) {
if (log.isEmpty) {
return const SizedBox.shrink();
}
return Text(log[index], textAlign: TextAlign.center);
},
),
),
OutlinedButton(
onPressed: () {
Navigator.of(context).push<void>(
MaterialPageRoute<void>(
builder: (BuildContext context) => const NextPage(),
),
);
},
child: const Text('Go to next page'),
),
],
),
),
),
);

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:flutter_api_samples/widgets/routes/route_observer.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
@ -38,5 +39,24 @@ void main() {
// Check the RouteObserver logs after the route is popped again.
expect(find.text('didPush'), findsOneWidget);
expect(find.text('didPopNext'), findsNWidgets(2));
// Check if any overflow or layout exceptions occurred.
expect(tester.takeException(), isNull);
});
testWidgets(
'RouteObserver example renders without overflow on small screens',
(WidgetTester tester) async {
// Set the screen size to a smaller value.
tester.view.physicalSize = const Size(200, 200);
addTearDown(tester.view.reset);
// Build the RouteObserver example widget.
await tester.pumpWidget(const example.RouteObserverApp());
await tester.pumpAndSettle();
// Verify there are no layout exceptions.
expect(tester.takeException(), isNull);
},
);
}