Skip to content

Instantly share code, notes, and snippets.

@ken-ty
Last active May 16, 2023 23:20
Show Gist options
  • Select an option

  • Save ken-ty/991b19fd187146cde872ff0505fa96ae to your computer and use it in GitHub Desktop.

Select an option

Save ken-ty/991b19fd187146cde872ff0505fa96ae to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
// 1. 必要最小限で実行
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: RichText(
text: const TextSpan(text: 'Hello World'),
),
),
),
);
// 2. コメントアウトを外し, Appを2回走らせる
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: RichText(
text: const TextSpan(text: 'Hello Shanghai'),
),
),
),
);
}
@ken-ty
Copy link
Copy Markdown
Author

ken-ty commented May 16, 2023

flutter プロジェクトを作成し, main にこれを貼ると確認できる.
https://www.youtube.com/watch?v=996ZgFRENMs&ab_channel=Flutter に出てきたコードです.

@ken-ty
Copy link
Copy Markdown
Author

ken-ty commented May 16, 2023

エラー

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:63050/rOMmVk0U_Kk=/ws

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown attaching to the render tree:
No Directionality widget found.

RichText widgets require a Directionality widget ancestor.
The specific widget that could not find a Directionality ancestor was: RichText
    softWrap: wrapping at box width
    maxLines: unlimited
    text: "Hello World"
    dirty
The ownership chain for the affected widget is: "RichText ← [root]"

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.

When the exception was thrown, this was the stack
#0      debugCheckHasDirectionality.<anonymous closure>
#1      debugCheckHasDirectionality
#2      RichText.createRenderObject
#3      RenderObjectElement.mount
#4      MultiChildRenderObjectElement.mount
#5      Element.inflateWidget
#6      Element.updateChild
#7      RenderObjectToWidgetElement._rebuild
#8      RenderObjectToWidgetElement.mount
#9      RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure>
#10     BuildOwner.buildScope
#11     RenderObjectToWidgetAdapter.attachToRenderTree
#12     WidgetsBinding.attachRootWidget
#13     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure>
#17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
(elided 3 frames from class _Timer and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════
E/SurfaceSyncer( 5049): Failed to find sync for id=0
W/Parcel  ( 5049): Expecting binder but got null!

@ken-ty
Copy link
Copy Markdown
Author

ken-ty commented May 16, 2023

エラーは MaterialApp ないから発生していたので追加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment