Repository navigation
[go_router] Expose Navigator.clipBehavior to ShellRoute #131836
Copy link
Copy link
Closed
flutter/packages
#12646Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectfound in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
When adding padding to the builder of a MaterialApp, you can see that the router clips its children. This is demonstrated best by creating a GoRoute with a big box shadow.
This gets problematic when using a ShellRoute, where a child route has a container with a box shadow. The box shadow gets clipped, looks off and does not fulfil the requirements of the design team.
To experience this behavior firsthand, you can test the code sample provided below.
Expected results
The box shadow should spread in all directions.
Actual results
The box shadow only spreads left and top and is clipped right and bottom.
Code sample
Basic code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Demo',
builder: (context, child) => Padding(
padding: const EdgeInsets.all(32),
child: child,
),
routerConfig: GoRouter(
routes: [
GoRoute(
path: "/",
builder: (context, state) => Container(
margin: const EdgeInsets.only(left: 100, top: 100),
decoration: const BoxDecoration(
color: Colors.red,
boxShadow: [
BoxShadow(
blurRadius: 50,
offset: (Offset(20, 20)),
),
],
),
),
),
],
),
);
}
}Code sample in the context of a ShellRoute
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Demo',
routerConfig: GoRouter(
routes: [
ShellRoute(
builder: (context, state, child) => MyHomePage(child: child),
routes: [
GoRoute(
path: "/",
builder: (context, state) => const MySubPage(),
),
],
),
],
),
);
}
}
class MyHomePage extends StatelessWidget {
final Widget child;
const MyHomePage({
super.key,
required this.child,
});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
Container(
width: 100,
color: Colors.green,
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(32),
child: child,
),
),
],
),
);
}
}
class MySubPage extends StatelessWidget {
const MySubPage({super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 100),
decoration: const BoxDecoration(
color: Colors.red,
boxShadow: [
BoxShadow(
blurRadius: 50,
offset: (Offset(20, 20)),
),
],
),
);
}
}Screenshots or Video
Logs
Logs
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.3.1 22E772610a darwin-arm64, locale en-DE)
• Flutter version 3.10.5 on channel stable at /Users/[user]/Development/src/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 796c8ef792 (7 weeks ago), 2023-06-13 15:51:02 -0700
• Engine revision 45f6e00911
• Dart version 3.0.5
• DevTools version 2.23.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/[user]/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E300c
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.80.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.70.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.3.1 22E772610a darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114
[✓] Network resources
• All expected network resources are available.
• No issues found!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectfound in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team

Activity
huycozy commentedon Aug 3, 2023
Hi @JakesMD
I see the same result in case no padding:
Instead, if you set margin for right and bottom of the Container, you will have the expected result, for eg:
JakesMD commentedon Aug 3, 2023
Thats still not the expected result. Without the router I get the expected result which looks like this:
Code for generating expected result
The shadow should have no flat or sharp edges. But don't forget that the shadow was just an example for a widget that overflows. You could have a stack with a positioned widget, for example:
Code for generating expected result
Code for generating actual result
huycozy commentedon Aug 4, 2023
Thanks for your update with more examples. I also check this with default route usage (without using
go_routerpackage), and see it outputs the expected result. The issue seems to bego_router's issue.Sample code using default route (expected result)
Demo default route (expected result)
Reproduced the issue with reproduction samples above (#131836 (comment), #131836 (comment))
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64, locale en-VN) • Flutter version 3.10.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (3 weeks ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 32.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode-beta.app/Contents/Developer • Build 15A5195m • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.80.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.68.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 13.5 22G74 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114 [✓] Network resources • All expected network resources are available. • No issues found!chunhtai commentedon Aug 10, 2023
Shellroute will clip the child; otherwise, the route transition like material route transition may overflow the box. If you are suggesting the box shadow shouldn't be clip, I think then this is more of a framework issue
12 remaining items
[-][go_router] Routes get clipped[/-][+][go_router] Expose Navigator.clipBehavior to ShellRoute[/+]JakesMD commentedon Aug 19, 2023
I tried it out for my self by adding
clipBehavior: Clip.noneto the Navigator and the page transition didn't look broken. The only difference it makes is that the sub route animates over the shell route, which is not a problem in our case. And definitely a sacrifice worth paying in order have no horribly clipped shadows and animated widgets.Borlay commentedon Mar 7, 2024
Any news on this one? I'm having same problem.
Don't want to add margin to every child page when i could add padding inside shell page only once.
JakesMD commentedon Mar 9, 2024
Back then we simply edited the package code locally. It has changed a lot since then but you can set the clip behavior here. If required, you can pass the clip behaviour up the
RouteBuilderandGoRouterDelegateinto theGoRouter.sampaioletti commentedon May 27, 2025
I believe this also changes the expected behavior of
DropdownButtonFormFieldIn our application we have a DropDown in a list and it causes it to scroll for options even though there is enough room for the full list
[go_router] Expose Navigator clipBehavior on ShellRoute and StatefulS…