flutter_flutter/examples/api/lib/widgets/routes/route_observer.0.dart
Pacific 2c4e7ebfd9
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>
2025-12-10 20:53:33 +00:00

122 lines
3.1 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [RouteObserver].
final RouteObserver<ModalRoute<void>> routeObserver =
RouteObserver<ModalRoute<void>>();
void main() {
runApp(const RouteObserverApp());
}
class RouteObserverApp extends StatelessWidget {
const RouteObserverApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: <NavigatorObserver>[routeObserver],
home: const RouteObserverExample(),
);
}
}
class RouteObserverExample extends StatefulWidget {
const RouteObserverExample({super.key});
@override
State<RouteObserverExample> createState() => _RouteObserverExampleState();
}
class _RouteObserverExampleState extends State<RouteObserverExample>
with RouteAware {
List<String> log = <String>[];
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
}
@override
void didPush() {
// Route was pushed onto navigator and is now the topmost route.
log.add('didPush');
}
@override
void didPopNext() {
// Covering route was popped off the navigator.
log.add('didPopNext');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: 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);
},
),
),
OutlinedButton(
onPressed: () {
Navigator.of(context).push<void>(
MaterialPageRoute<void>(
builder: (BuildContext context) => const NextPage(),
),
);
},
child: const Text('Go to next page'),
),
],
),
),
),
);
}
}
class NextPage extends StatelessWidget {
const NextPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Go back to RouteAware page'),
),
),
);
}
}