以下の内容はhttps://appdev.blitz-time.com/entry/2021/01/10/095954より取得しました。


【Flutter開発】TextPainter.textDirection must be set to a non-null value before using the TextPainter.

Canvasにテキストを描画したいのですが、適当に書いたらエラーになりました。。。

TextSpan span = new TextSpan(text: 'テキスト');
TextPainter tp = new TextPainter(text: span, textAlign: TextAlign.left);
tp.layout();
tp.paint(canvas, new Offset(5.0, 5.0));

とすると、

TextPainter.textDirection must be set to a non-null value before using the TextPainter.
'package:flutter/src/painting/text_painter.dart':
Failed assertion: line 554 pos 12: 'textDirection != null'

とでる。

TextPainterに「textDirection: TextDirection.ltr」の指定が必要だそうです。

TextPainter tp = new TextPainter(text: span, textAlign: TextAlign.left, textDirection: TextDirection.ltr);

デフォルトで指定があってもよさそうですねどね。。。。
何か事前のお作法を忘れているかもしれません。




以上の内容はhttps://appdev.blitz-time.com/entry/2021/01/10/095954より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14