Skip to content

Improve documentation and assert for Stack.textDirection; also, API docs for Localizations should admit to adding a Directionality #13013

Closed

Description

@ErikUggeldahl

Steps to Reproduce

The following empty Stack layout trips an assertion.

import 'package:flutter/widgets.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  MyApp() {
  }

  @override
  Widget build(BuildContext context) {
    return new Stack();
  }
}

Logs

I/flutter (24950): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (24950): The following assertion was thrown during performLayout():
I/flutter (24950): 'package:flutter/src/painting/alignment.dart': Failed assertion: line 513 pos 12: 'direction !=
I/flutter (24950): null': is not true.
I/flutter (24950): 
I/flutter (24950): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (24950): more information in this error message to help you determine and fix the underlying cause.
I/flutter (24950): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (24950):   https://github.com/flutter/flutter/issues/new
I/flutter (24950): 
I/flutter (24950): When the exception was thrown, this was the stack:
I/flutter (24950): #2      AlignmentDirectional.resolve (package:flutter/src/painting/alignment.dart:513:12)
I/flutter (24950): #3      RenderStack._resolve (package:flutter/src/rendering/stack.dart:327:36)
I/flutter (24950): #4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:436:5)
I/flutter (24950): #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter (24950): #6      RenderView.performLayout (package:flutter/src/rendering/view.dart:142:13)
I/flutter (24950): #7      RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1837:7)
I/flutter (24950): #8      PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1126:18)
I/flutter (24950): #9      BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:262:19)
I/flutter (24950): #10     BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:581:22)
I/flutter (24950): #11     BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:200:5)
I/flutter (24950): #12     BindingBase&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:713:15)
I/flutter (24950): #13     BindingBase&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:649:9)
I/flutter (24950): #14     BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/rendering/binding.dart:286:20)
I/flutter (24950): #16     _Timer._runTimers (dart:isolate-patch/dart:isolate/timer_impl.dart:367)
I/flutter (24950): #17     _Timer._handleMessage (dart:isolate-patch/dart:isolate/timer_impl.dart:401)
I/flutter (24950): #18     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:163)
I/flutter (24950): (elided 3 frames from class _AssertionError and package dart:async-patch)
I/flutter (24950): 
I/flutter (24950): The following RenderObject was being processed when the exception was fired:
I/flutter (24950):   RenderStack#46ac0 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (24950):   creator: Stack ← MyApp ← [root]
I/flutter (24950):   parentData: <none>
I/flutter (24950):   constraints: BoxConstraints(w=1024.0, h=768.0)
I/flutter (24950):   size: MISSING
I/flutter (24950):   alignment: AlignmentDirectional.topStart
I/flutter (24950):   textDirection: null
I/flutter (24950):   fit: loose
I/flutter (24950):   overflow: clip
I/flutter (24950): This RenderObject has no descendants.
I/flutter (24950): ════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor

[✓] Flutter (on Mac OS X 10.13.1 17B48, locale en-CA, channel alpha)
    • Flutter at /Users//flutter/flutter
    • Framework revision e8aa40eddd (4 weeks ago), 2017-10-17 15:42:40 -0700
    • Engine revision 7c4142808c
    • Tools Dart version 1.25.0-dev.11.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
    • Android SDK at /Users//Library/Android/sdk
    • Platform android-25, build-tools 25.0.3
    • ANDROID_HOME = /Users//Library/Android/sdk
    • 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.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.1, Build version 9B55
    • 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 Community Edition (version 2017.2.5)
    • Flutter plugin version 18.2
    • Dart plugin version 172.4155.35

[✓] Connected devices
    • SM T810 • 33003b44d0cd3317 • android-arm • Android 7.0 (API 24) (emulator)

Activity

  1. Hixie commented on Nov 14, 2017

    @Hixie
    Contributor

    Yeah, you don't have a textDirection argument, which is required if you don't have a Directionality widget, which you don't have either.

    We should definitely make that clearer though.

  2. added
    c: crashStack traces logged to the console
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Nov 14, 2017
  3. added this to the 3: Current Milestone milestone on Nov 14, 2017
  4. ErikUggeldahl commented on Nov 14, 2017

    @ErikUggeldahl
    Author

    Thanks Ian. I knew it was likely something on my end, but agreed, the error isn't clear on resolution steps. My humble suggestion would be to catch it higher in the stack with a clear assertion.

  5. ErikUggeldahl commented on Nov 14, 2017

    @ErikUggeldahl
    Author

    As a note, I was curious if this would also trigger an assert if a WidgetApp (or MaterialApp) was used as the base widget. When it didn't, I used debugDumpApp() and discovered the tree did indeed include a Directionality widget.

             WidgetsApp-[GlobalObjectKey _MaterialAppState#d840c](state: _WidgetsAppState#c06b3)
             └MediaQuery(MediaQueryData(size: Size(1024.0, 768.0), devicePixelRatio: 2.0, textScaleFactor: 1.0, padding: EdgeInsets(0.0, 24.0, 0.0, 0.0)))
              └Localizations(locale: en_US, delegates: [_MaterialLocalizationsDelegate[MaterialLocalizations], _WidgetsLocalizationsDelegate[WidgetsLocalizations]], state: _LocalizationsState#7f97f)
               └_LocalizationsScope-[GlobalKey#a76f0]
                └Directionality(textDirection: ltr)
    

    It turns out this is included by the Localizations widget, though this isn't mentioned anywhere in its documentation. Perhaps it should be?

  6. Hixie commented on Nov 15, 2017

    @Hixie
    Contributor

    Yeah we should document that too.

  7. changed the title [-]Assertion tripped with empty Stack layout[/-] [+]Improve documentation and assert for Stack.textDirection; also, API docs for Localizations should admit to adding a Directionality[/+] on Dec 20, 2017
  8. modified the milestones: 3: Current Milestone, on Dec 20, 2017
  9. goderbauer commented on Apr 22, 2020

    @goderbauer
    Member
  10. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  11. self-assigned this
    on Jul 2, 2020
  12. modified the milestones: , 1.21 - July 2020 on Jul 2, 2020
  13. github-actions commented on Aug 19, 2021

    @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.

  14. locked as resolved and limited conversation to collaborators on Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkc: crashStack traces logged to the consoled: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.waiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions