inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[코드팩토리] [초급] Flutter 3.0 앱 개발 - 10개의 프로젝트로 오늘 초보 탈출!

가운데정렬 이안되여

404

YOUNGJAE KIM

작성한 질문수 2

0

import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        bottom: false,
        child: Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.black,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Container(color: Colors.red, width: 50, height: 50),
                  Container(color: Colors.orange, width: 50, height: 50),
                  Container(color: Colors.yellow, width: 50, height: 50),
                  Container(color: Colors.green, width: 50, height: 50),
                ],
              ),
              Row(
                children: [
                  Container(color: Colors.orange, width: 50, height: 50),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Container(color: Colors.red, width: 50, height: 50),
                  Container(color: Colors.orange, width: 50, height: 50),
                  Container(color: Colors.yellow, width: 50, height: 50),
                  Container(color: Colors.green, width: 50, height: 50),
                ],
              ),
              Row(children: [
                Container(color: Colors.green, width: 50, height: 50),
              ],),
            ],
          ),
        ),
      ),
    );
  }
}

flutter 클론코딩

답변 2

0

코드팩토리

안녕하세요!

어떤 부분을 가온데 정렬 하고싶은건지 정확히 말씀 주시면 다시 답변 드리겠습니다.

감사합니다!

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.

다음과 같이 코드를 수정하시면 가운데 정렬이 가능해집니다.

import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        bottom: false,
        child: Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.black,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(color: Colors.red, width: 50, height: 50),
                  Container(color: Colors.orange, width: 50, height: 50),
                  Container(color: Colors.yellow, width: 50, height: 50),
                  Container(color: Colors.green, width: 50, height: 50),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(color: Colors.orange, width: 50, height: 50),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(color: Colors.red, width: 50, height: 50),
                  Container(color: Colors.orange, width: 50, height: 50),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

위의 코드에서 mainAxisAlignmentcrossAxisAlignmentMainAxisAlignment.center로 수정하고, 필요한 곳에 Row를 추가하였습니다. 그리고 keyKey? key로 수정해주시면 됩니다.

수정한 코드를 실행해보시고 정렬이 제대로 되는지 확인해보세요. 추가적인 질문이 있으시면 언제든지 물어보세요. 좋은 하루 보내세요!

198강 (){onTap(e);}의 이해 돕기

0

39

1

video_call 플러그인 설치후 에러 발생

0

47

1

SDK 안드로이드 설치 질문!

0

62

1

코드팩토리 디스코드 링크 다시 부탁드려요~

0

92

1

Webview를 이용해서 URL 상의 페이지 출력 불가

0

71

1

홈스크린 함수를 함축해서 main.dart에 옮기는 문제

0

56

1

플레이스토어

0

60

1

아고라 엔진 init 함수의 반환타입이 Future<void> 이것의 의미는 무엇인가요?

0

56

1

가이드라인 질문

0

59

0

emulator 에러 환경설정 뭐가 문제 일까요??

0

78

1

emulator 실행 오류

0

95

3

Column을 가로방향 최대 사이즈를 차지하도록 하는 방법에 관련

0

73

1

pubspec.yaml에서 font를 추가하면서 weight 값을 지정하는 것이 의미가 있는 것인지 문의

0

44

1

setState()를 호출하지 않으면 build가 실행 안되는 건가요?

0

54

1

video_call 플러그인 설치시 에러문제

0

67

1

children 안의 if 문에서 { } 못쓰는 이유?

0

51

1

이렇게 오류가 떠요

0

66

1

AppBar 사용했는데

0

63

2

[문제해결] '오늘도 출첵!' 의 171번 강의에서 중요한 문제를 발견했습니다

0

58

1

StatefulWidget 실습 에러가 발생합니다.[해결완료]

0

65

1

Video Player 프로젝트에 대한 추가 질문

0

54

0

Row위젯이나 column위젯의 위치는 누가 정하나요??

0

43

1

geolocator 오류때문에 개발진행이 불가능입니다

0

64

1

API 관련 이슈

0

89

2