mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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 |  | | A |  | ## 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:
parent
f8b88be694
commit
2c4e7ebfd9
@ -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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -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);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user