こんにちは、フラメルです。
今回はColumn
やRow
などで使用されるCrossAxisAlignment
の使い方と種類について紹介します。
目次
CrossAxisAlignmentとは?


CrossAxisAlignment
を使用することでColumn
なら横軸、Row
なら縦軸とクロス軸における子要素の配置を指定できます。
Column
とRow
どちらも軸が変わるだけで同様に使用できます。今回はColumnを使用してCrossAxisAlignment
の種類を紹介します。
CrossAxisAlignment.start

crossAxisAlignment: CrossAxisAlignment.start
CrossAxisAlignment.start
ではクロス軸の開始位置に最も近い位置に要素が配置されます。
Column
ではtextDirection
でクロス軸の開始位置を指定できます。
CrossAxisAlignment.end

crossAxisAlignment: CrossAxisAlignment.center
CrossAxisAlignment.end
ではクロス軸の開始位置から最も離れた位置に要素が配置されます。
CrossAxisAlignment.center

crossAxisAlignment: CrossAxisAlignment.center
CrossAxisAlignment.center
では中央に配置されます。
CrossAxisAlignment.stretch

crossAxisAlignment: CrossAxisAlignment.stretch
CrossAxisAlignment.stretch
では親要素に対して横幅いっぱいに広がります。
横幅いっぱいに広がらない場合はSizedBox(width: double.infinity)
を使用します。
あわせて読みたい


【Flutter】crossAxisAlignmentが効かない時の対処法
こんにちは、フラメルです。 今回はColumnやRowなどでcrossAxisAlignmentが効かない時の対処法を紹介します。 対処法:クロス軸の横幅をいっぱいにする SizedBoxあり Si…
以上です。