たろすの技術メモ

Jot Down the Tech

ソフトウェアエンジニアのメモ書き

Textウィジェットの引数に長い文字列を渡してもコードを読みやすくする方法

dart.dev

上記のページで知りました。

Textウィジェットの引数に長い文字列を渡す場合、改行しないとファイルが横長になり読みにくいですよね。

Text('ERROR: Parts of the spaceship are on fire. Other parts are overrun by martians. Unclear which are which.');

以下のようにしかできないと思ってましたが、

Text('''
ERROR: Parts of the spaceship are on fire. Other parts are overrun by martians. Unclear which are which.
''');

Text('ERROR: Parts of the spaceship are on fire. ' +
  'Other parts are overrun by martians. ' +
  'Unclear which are which.');

以下のようにできるようです(以前からでしたっけ?)。これでソースコードが見やすくなりますね。

Text(
    'ERROR: Parts of the spaceship are on fire. Other '
    'parts are overrun by martians. Unclear which are which.');