Repository navigation
Support non-uniform Borders with a non-zero borderRadius #12583
Copy link
Copy link
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
| assert(borderRadius == null, 'A borderRadius can only be given for uniform borders.'); |
new BoxDecoration(
color: color,
border: new Border(
left: new BorderSide(color: color),
top: new BorderSide(color: color),
bottom: new BorderSide(color: color),
),
borderRadius: new BorderRadius.only(
topLeft: new Radius.circular(radius),
bottomLeft: new Radius.circular(radius),
),
)Why can't I do this.
I get this error:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
A borderRadius can only be given for uniform borders.
'package:flutter/src/painting/box_border.dart': Failed assertion: line 462 pos 12: 'borderRadius ==
null'
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new
When the exception was thrown, this was the stack:
The following RenderObject was being processed when the exception was fired:
RenderDecoratedBox#9302a relayoutBoundary=up6
creator: DecoratedBox ← Container ← Listener ← _GestureSemantics ← RawGestureDetector ←
GestureDetector ← _CupertinoSegmentControlItem ← Row ← Padding ← Column ← CupertinoSegmentControl
← MediaQuery ← ⋯
decoration: BoxDecoration
RenderPadding#09d88 relayoutBoundary=up7 NEEDS-PAINT
RenderParagraph#85b48 relayoutBoundary=up8 NEEDS-PAINT
Flutter Doctor
[✓] Flutter (on Mac OS X 10.13 17A405, locale en-GB, channel master)
• Flutter at /Users/theobouwman/Development/flutter
• Framework revision ad72c78342 (19 hours ago), 2017-10-16 10:58:39 -0700
• Engine revision 7c4142808c
• Tools Dart version 1.25.0-dev.11.0
[✓] Android toolchain - develop for Android devices (Android SDK 26.0.1)
• Android SDK at /Users/theobouwman/Library/Android/sdk
• Platform android-26, build-tools 26.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.0, Build version 9A235
• ios-deploy 1.9.2
• CocoaPods version 1.3.1
[✓] Android Studio (version 2.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] IntelliJ IDEA Ultimate Edition (version 2017.2.5)
• Flutter plugin version 17.0
• Dart plugin version 172.4155.35
[✓] Connected devices
• iPhone X • 6EE42D9C-C0E5-4E0B-AB0C-AC343B53C4EF • ios • iOS 11.0 (simulator)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Activity
Hixie commentedon Oct 17, 2017
The first line of the error message gives you the answer: "A borderRadius can only be given for uniform borders."
Hixie commentedon Oct 17, 2017
(The reason being, there's no real separation between the "top" and "left" borders if there's a "topLeft" corner.)
theobouwman commentedon Oct 17, 2017
okay I understand. but how could I accomplish my needs?
Hixie commentedon Oct 17, 2017
What are your needs?
theobouwman commentedon Oct 17, 2017
I want to have a top, left and bottom border with a topleft and bottomleft borderRadius.
The cupertino_segement_control plugin I created (https://github.com/theobouwman/flutter_cupertino_segment_control/blob/master/lib/cupertino_segment_control.dart#L19) is currently limited to 3 items because I cannot find a way to create a BoxDecoration with 3 borders and 2 rounded corners.
Hixie commentedon Oct 17, 2017
Can you post an image showing how it should render?
jeroen-meijer commentedon May 8, 2018
Guess you can close this, right?
bramvbilsen commentedon May 9, 2018
Is it something like this that you want?

I've created a
CustomRoundedRectangleBorderclass for this, perhaps it'd be nice to have this in Flutter.@Hixie Do you think that'd go through as a PR?
jeroen-meijer commentedon May 10, 2018
@bramvbilsen That'd be nice. PR will get a higher chance of approval if you add some documentation. Is this
CustomRoundedRectangleBorderavailable anywhere, on your git perhaps?bramvbilsen commentedon May 10, 2018
@jeroen-meijer I've actually filed the PR yesterday. You can find it here: #17441
nokia6290 commentedon Sep 10, 2018
Has this been fixed?
I've encountered a similar problem. Except in my case I was creating custom BorderRadius with border at the same time and my text would disappear thats placed inside the Container. Eventually found a solution by leaving just BorderRadius and removing Border.
My code is:
I was not aware, but you can only have either border or borderRadius at the same time. If both are placed you get a conflict.
Maybe this will help someone.
TaroXin commentedon Sep 18, 2018
Is there a solution? I think I have the same problem
The same is true for log printed information
[-]Unable to create a BoxDecoration with 3 borders and borderRadius.[/-][+]Support non-uniform Borders with a non-zero borderRadius[/+]55 remaining items
chaudharydeepanshu commentedon Aug 3, 2022
Yeah totally agree with you on that man.
No issues I will create a package myself fixing the caveats in above solutions and then I will share it with the community.
cristian-eriomenco commentedon Aug 16, 2022
Assembly is easy as well when you know what you're doing. But we choose higher level abstractions for a good reason. Form controls development & styling them is something should be most feature rich and customizable.
The frustration comes from the fact, there is a concept of controlling specific borders and their radius but it doesn't work.
Pixel shifting, masking, overlaying, cropping when dealing with a button doesn't give you a sense of confidence that your solution would be working correctly and perform well on all platforms.
A hack here, another there... Here is a special case... there is shim... this is border-box, that is content-box.
A new version came out! Oh do I need to revisit my hacks? Or should I just leave them as I don't remember anyway what I was trying to achieve there...
akarabach commentedon Oct 11, 2022
any updates here ? 5 years long...
KevinVan720 commentedon Oct 11, 2022
Check this package out: https://pub.dev/packages/morphable_shape
nzkn commentedon Jan 2, 2023
Still not fixed?
TheStrongest commentedon Jan 4, 2023
It's strange that this issue is yet to get a fix after 5 years.
chornbe commentedon Jan 4, 2023
dalewking commentedon Jan 4, 2023
I just want to note that this issue is with BoxBorder, but there is also ShapeBorder that does not have this issue (I am using that on another project that I want the shape rounded on 2 corners). So perhaps that is usable for some of the use cases.
ilyosbekkk commentedon Feb 5, 2023
is there any updates on this issue?
eldarkk commentedon Feb 8, 2023
For hiding some borders, Stack with white layer above saved my month.
ak1987 commentedon Feb 10, 2023
A very old-school css solution from ancient times when rounded corners were made by 4 background images in 4 divs.
The code above gives top-rounded container with no bottom border:
bernaferrari commentedon Mar 4, 2023
I (finally) made a package for a shape border that does non-uniform borders (multiple widths, same color). https://github.com/bernaferrari/non_uniform_border
I'm also submitting a PR for adding it into Border (BoxDecoration). I don't like, I prefer ShapeDecoration, but then you can choose between using my package or BoxDecoration.
github-actions commentedon Apr 7, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.