Skip to content

Better BoxDecoration directionality error message #88644

Description

@nt4f04uNd

Disclaimer - this issue was picked for an entertaining-new-contributors educational project inside Yandex mobile schools. Please contact @nt4f04uNd that you are willing to work on it.

Running this code sample

import 'package:flutter/material.dart';

void main() {
  runApp(Container(
    decoration: BoxDecoration(
      border: Border.all(),
      borderRadius: BorderRadiusDirectional.all(Radius.circular(1.0)),
    ),
  ));
}

Gives this as output

Gives this as output
════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during paint():
'package:flutter/src/painting/border_radius.dart': Failed assertion: line 727 pos 12: 'direction != null': is not true.
2

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?template=2_bug.md

The relevant error-causing widget was
Container Container:file:///C:/dev/projects/issues/lib/main.dart:10:12
When the exception was thrown, this was the stack
#2      BorderRadiusDirectional.resolve
package:flutter/…/painting/border_radius.dart:727
#3      _BoxDecorationPainter.paint
package:flutter/…/painting/box_decoration.dart:488
#4      RenderDecoratedBox.paint
package:flutter/…/rendering/proxy_box.dart:2162
#5      RenderObject._paintWithContext
package:flutter/…/rendering/object.dart:2409
#6      PaintingContext.paintChild
package:flutter/…/rendering/object.dart:189
#7      RenderView.paint
package:flutter/…/rendering/view.dart:209
#8      RenderObject._paintWithContext
package:flutter/…/rendering/object.dart:2409
#9      PaintingContext._repaintCompositedChild
package:flutter/…/rendering/object.dart:141
#10     PaintingContext.repaintCompositedChild
package:flutter/…/rendering/object.dart:100
#11     PipelineOwner.flushPaint
package:flutter/…/rendering/object.dart:979
#12     RendererBinding.drawFrame
package:flutter/…/rendering/binding.dart:455
#13     WidgetsBinding.drawFrame
package:flutter/…/widgets/binding.dart:883
#14     RendererBinding._handlePersistentFrameCallback
package:flutter/…/rendering/binding.dart:319
#15     SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1143
#16     SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1080
#17     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
package:flutter/…/scheduler/binding.dart:863
(elided 13 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
The following RenderObject was being processed when the exception was fired: RenderDecoratedBox#ef365
RenderObject: RenderDecoratedBox#ef365
    parentData: <none>
    constraints: BoxConstraints(w=392.7, h=759.3)
    size: Size(392.7, 759.3)
    decoration: BoxDecoration
        border: Border.all(BorderSide(Color(0xff000000), 1.0, BorderStyle.solid))
        borderRadius: BorderRadiusDirectional.circular(1.0)
    configuration: ImageConfiguration(bundle: PlatformAssetBundle#6a1dc(), devicePixelRatio: 1.0, platform: android)
    child: RenderPadding#0d2c7 NEEDS-PAINT
        parentData: <none> (can use size)
        constraints: BoxConstraints(w=392.7, h=759.3)
        size: Size(392.7, 759.3)
        padding: EdgeInsets.all(1.0)
        child: RenderLimitedBox#7356c NEEDS-PAINT
            parentData: offset=Offset(1.0, 1.0) (can use size)
            constraints: BoxConstraints(w=390.7, h=757.3)
            size: Size(390.7, 757.3)
            maxWidth: 0.0
            maxHeight: 0.0
            child: RenderConstrainedBox#fdce1 NEEDS-PAINT
                parentData: <none> (can use size)
                constraints: BoxConstraints(w=390.7, h=757.3)
                size: Size(390.7, 757.3)
                additionalConstraints: BoxConstraints(biggest)
════════════════════════════════════════════════════════════════════════════════

It would be nice if that would be catched and rethrown with a better error message instructing what I have to do to fix that - similar to the assertion here

bool debugCheckHasDirectionality(BuildContext context, { String? why, String? hint, String? alternative }) {
assert(() {
if (context.widget is! Directionality && context.getElementForInheritedWidgetOfExactType<Directionality>() == null) {
why = why == null ? '' : ' $why';
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('No Directionality widget found.'),
ErrorDescription('${context.widget.runtimeType} widgets require a Directionality widget ancestor$why.\n'),
if (hint != null)
ErrorHint(hint),
context.describeWidget('The specific widget that could not find a Directionality ancestor was'),
context.describeOwnershipChain('The ownership chain for the affected widget is'),
ErrorHint(
'Typically, the Directionality widget is introduced by the MaterialApp '
'or WidgetsApp widget at the top of your application widget tree. It '
'determines the ambient reading direction and is used, for example, to '
'determine how to lay out text, how to interpret "start" and "end" '
'values, and to resolve EdgeInsetsDirectional, '
'AlignmentDirectional, and other *Directional objects.',
),
if (alternative != null)
ErrorHint(alternative),
]);
}
return true;
}());
return true;
}

Activity

  1. darshankawar commented on Aug 23, 2021

    @darshankawar
    Member

    @nt4f04uNd

    On latest master, I see the same error log as you posted:

    
    ======== Exception caught by rendering library =====================================================
    The following assertion was thrown during paint():
    'package:flutter/src/painting/border_radius.dart': Failed assertion: line 727 pos 12: 'direction != null': is not true.
    
    
    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?template=2_bug.md
    
    

    On latest stable though, it seems to be a bit better ?

    
    ======== Exception caught by rendering library =====================================================
    The following _CastError was thrown during paint():
    type 'BorderRadiusDirectional' is not a subtype of type 'BorderRadius?' in type cast
    
    The relevant error-causing widget was: 
      Container file:///Users/dhs/Documents/NCFlutter/bug_test/lib/main.dart:4:10
    When the exception was thrown, this was the stack: 
    #0      _BoxDecorationPainter.paint (package:flutter/src/painting/box_decoration.dart:488:46)
    #1      RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:2143:17)
    #2      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2317:7)
    #3      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
    #4      RenderView.paint (package:flutter/src/rendering/view.dart:200:15)
    

    type 'BorderRadiusDirectional' is not a subtype of type 'BorderRadius?' in type cast which seems to give an indication what's wrong with the implementation and hence the error.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 23, 2021
  3. nt4f04uNd commented on Aug 23, 2021

    @nt4f04uNd
    MemberAuthor

    It is a fixed crash, see #88039. On stable it wouldn't resolve even if you wrapped the container with the Directionality.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 23, 2021
  5. added
    a: error messageError messages from the Flutter framework
    a: qualityA truly polished experience
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    and removed
    in triagePresently being triaged by the triage team
    on Aug 24, 2021
  6. 4 remaining items

  7. added
    P3Issues that are less important to the Flutter project
    triaged-designTriaged by Design Languages team
    on Jun 18, 2025
  8. self-assigned this
    on Jul 2, 2025
  9. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jul 10, 2025
  10. github-actions commented on Jul 24, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: error messageError messages from the Flutter frameworka: qualityA truly polished experienceframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions