memostack
article thumbnail
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.tistory.com/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
반응형

Column 위젯을 가로로 정렬할때는 crossAxisAlignment 속성을 이용한다.

 

CrossAxisAlignment.start

startdefault 값으로 왼쪽에 붙게 한다.

import "package:flutter/material.dart";

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Column CrossAxisAlignment 예제",
      home: Example(),
    );
  }
}

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          // Column 위젯 추가
          child: Column(
            // start 속성
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                color: Colors.blue,
                width: 100,
                height: 100,
                child: Text("컨테이너"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

start 속성

 

CrossAxisAlignment.center

child 위젯을 가운데로 위치시키는 역할을 한다.

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          // Column 위젯 추가
          child: Column(
            // center 속성
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                color: Colors.blue,
                width: 100,
                height: 100,
                child: Text("컨테이너"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

center 속성

 

 

CrossAxisAlignment.end

컨테이너의 맨 오른쪽으로 붙게 하는 역할을 한다.

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          // Column 위젯 추가
          child: Column(
            // end 속성
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Container(
                color: Colors.blue,
                width: 100,
                height: 100,
                child: Text("컨테이너"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

end 속성

 

 

CrossAxisAlignment.strech

가로로 최대로 확장할때 stretch 속성을 사용한다.

child 위젯에 width 값이 설정되어 있지만, 무시되고 최대로 확장된다.

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          // Column 위젯 추가
          child: Column(
            // stretch 속성
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                color: Colors.blue,
                width: 100,
                height: 100,
                child: Text("컨테이너"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

strech 속성

 

 


다른 글

2021/01/02 - [Flutter] - 플러터(flutter) - Column 세로 정렬 방법 (MainAxisAlignment)

 

플러터(flutter) - Column 세로 정렬 방법 (MainAxisAlignment)

MainAxisAlignment 속성을 이용하여 Column의 child 위젯을 정렬할 수 있다. 웹 개발을 해본 사람은 쉽게 이해할 수 있다. 기본 코드 import "package:flutter/material.dart"; void main() => runApp(MyApp()); c..

memostack.tistory.com

2021/01/02 - [Flutter] - 플러터(flutter) - Container와 SizedBox의 차이

 

플러터(flutter) - Container와 SizedBox의 차이

Container 와 SizedBox 위젯은 둘 다 width 와 height 를 가진다. 그래서 너비와 높이를 설정할 수 있다. 하지만 차이점이 존재한다. Container Container 의 위젯은 width와 height를 넣지 않으면, 최대 크기로..

memostack.tistory.com

 

반응형
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.tistory.com/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
profile

memostack

@bluemiv_mm

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!