Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A borderRadius can only be given for uniform borders

I am getting a warning when using following code but my app is running fine:

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during paint():
A borderRadius can only be given for uniform borders.
'package:flutter/src/painting/box_border.dart':
Failed assertion: line 510 pos 12: 'borderRadius == null'

Here is my code:

           Container(
              height: screenSize.height*.13,
              width: AppSize.medium,
              decoration: BoxDecoration(
                color: Colors.red,
                border: Border(
                  right: BorderSide(
                    width: 1.0,
                    color: Colors.blue
                  ),
                ),
                borderRadius: BorderRadius.only(
                  topRight: Radius.circular(AppSize.small),
                  bottomRight: Radius.circular(AppSize.small),
                )
              ),
            )
like image 499
Code Hunter Avatar asked Nov 12 '19 05:11

Code Hunter


People also ask

Is it possible to add border and borderradius at the same time?

It's not possible to add border: and borderRadius: at the same time, you'll get this error: A borderRadius can only be given for uniform borders. You can achieve what you want using the borderRadius: and a boxShadow: instead of border: like this:

Is it possible to give a border radius for a boxshadow?

A borderRadius can only be given for uniform borders. You can achieve what you want using the borderRadius: and a boxShadow: instead of border: like this:

Why does flutter keep throwing assertion errors when applying border radius?

Flutter is complaining because you only apply a right border to your container, but want to have a border radius as well. Flutter expects the border to be uniform, i.e. all the way around and in the same color, when applying border radius. If you jump to the sources where the assertion error was thrown you can have a look at the actual assertion.

Why is flutter complaining about my container border?

Flutter is complaining because you only apply a right border to your container, but want to have a border radius as well. Flutter expects the border to be uniform, i.e. all the way around and in the same color, when applying border radius.


1 Answers

This is the easiest way that I could came up with... as you can see there's 2 container, the color of outer container is actually the color of the border and the margin of inner container is the strokeWidth of the border and the color of inner container is the background color.

Container(
  decoration: BoxDecoration(
    color: Colors.grey[400],

    borderRadius: BorderRadius.only(
      topLeft: const Radius.circular(15.0),
      topRight: const Radius.circular(15.0),
    ),// BorderRadius

  ),// BoxDecoration
  child: Container(
    margin: const EdgeInsetsDirectional.only(start: 2, end: 2, top: 2),
    decoration: BoxDecoration(
      color: Colors.grey[300],

      borderRadius: BorderRadius.only(
        topLeft: const Radius.circular(13.0),
        topRight: const Radius.circular(13.0),
      ),// BorderRadius

    ),// BoxDecoration
  ),// Container
),// Container

It's a bit silly answer but works! ;)

like image 154
ehsaneha Avatar answered Oct 06 '22 04:10

ehsaneha