前回の続きで他のレイアウトについて、触れていきたいと思います。
環境
 ・MacOS Ventura 13.6.3
 ・Xcode 15.1
 ・VSCode 1.85.1
 ・Flutter 3.16.5
 ・Dart 3.2.3


前回の続きで他のレイアウトについて、触れていきたいと思います。
 ・MacOS Ventura 13.6.3
 ・Xcode 15.1
 ・VSCode 1.85.1
 ・Flutter 3.16.5
 ・Dart 3.2.3

SafeArea(
  child: Align(
    alignment: Alignment.center,
    child: Container(
      width: 200,
      height: 200,
      color: Colors.grey,
      child: const OverflowBox(
        maxWidth: 300,
        maxHeight: 300,
        child: FlutterLogo(size: 300),
      ),
    ),
  ),
),
SafeArea(
  child: Align(
    alignment: Alignment.center,
    child: Container(
      width: 200,
      height: 200,
      color: Colors.grey,
      child: Center(
        child: SizedOverflowBox(
          alignment: Alignment.topCenter,
          size: const Size(100, 100),
          child: Container(
            width: 150,
            height: 20,
            color: Colors.blue,
          ),
        ),
      ),
    ),
  ),
),
SafeArea(
  child: SizedBox.expand(
    child: FractionallySizedBox(
      widthFactor: 0.5,
      heightFactor: 0.5,
      alignment: FractionalOffset.center,
      child: ColoredBox(
        color: Colors.blue,
      ),
    ),
  ),
),
SafeArea(
  child: Container(
    color: Colors.grey,
    alignment: Alignment.center,
    height: 100,
    child: AspectRatio(
      aspectRatio: 16 / 9,
      child: Container(
        color: Colors.blue,
      ),
    ),
  ),
),SafeArea(
  child: Align(
    alignment: Alignment.topCenter,
    child: Container(
      color: Colors.grey,
      alignment: Alignment.center,
      width: 100,
      height: 100,
      child: AspectRatio(
        aspectRatio: 2,
        child: Container(
          width: 50,
          height: 20,
          color: Colors.blue,
        ),
      ),
    ),
  ),
),
</code></pre>
コード例だと、親ウィジェットは、幅、高さともに100の領域の灰色の領域に対し、青の領域を指定サイズでは幅50×高さ20を指定にしていますが、 AspectRatio ウィジェットの制約が優先されます。
そのため、幅:高さのアスペクト比を2:1で調整するため、幅100×高さ50になり、中央位置で表示されます。
<pre><code>
SafeArea(
  child: Align(
    alignment: Alignment.topCenter,
    ch
SafeArea(
  child: Align(
    alignment: Alignment.topCenter,
    child: Container(
      color: Colors.blue,
      width: 200,
      height: 300,
      child: const FittedBox(
        fit: BoxFit.fill,
        child: Placeholder(),
      ),
    ),
  ),
),今回は、続きでレイアウトの知識を深めるのを目的に記事を書きました。
今まで、子ウィジェットが単一の場合のレイアウト制御で、他にもありますが、一旦、次回から、複数の子ウィジェットのレイアウトやそれらを使った応用した例などでレイアウトの知識を深める予定です。