가운데정렬 이안되여
410
작성한 질문수 2
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),
],),
],
),
),
),
);
}
}
답변 2
0
안녕하세요, 인프런 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),
],
),
],
),
),
),
);
}
}
위의 코드에서 mainAxisAlignment과 crossAxisAlignment를 MainAxisAlignment.center로 수정하고, 필요한 곳에 Row를 추가하였습니다. 그리고 key를 Key? key로 수정해주시면 됩니다.
수정한 코드를 실행해보시고 정렬이 제대로 되는지 확인해보세요. 추가적인 질문이 있으시면 언제든지 물어보세요. 좋은 하루 보내세요!
[강의 문의] '앱 출시하기' 강의 추가 일정 관련하여 문의드립니다.
0
44
1
198강 (){onTap(e);}의 이해 돕기
0
81
1
video_call 플러그인 설치후 에러 발생
0
98
1
SDK 안드로이드 설치 질문!
0
105
1
코드팩토리 디스코드 링크 다시 부탁드려요~
0
133
1
Webview를 이용해서 URL 상의 페이지 출력 불가
0
116
1
홈스크린 함수를 함축해서 main.dart에 옮기는 문제
0
97
1
플레이스토어
0
90
1
아고라 엔진 init 함수의 반환타입이 Future<void> 이것의 의미는 무엇인가요?
0
87
1
가이드라인 질문
0
78
0
emulator 에러 환경설정 뭐가 문제 일까요??
0
121
1
emulator 실행 오류
0
151
3
Column을 가로방향 최대 사이즈를 차지하도록 하는 방법에 관련
0
99
1
pubspec.yaml에서 font를 추가하면서 weight 값을 지정하는 것이 의미가 있는 것인지 문의
0
75
1
setState()를 호출하지 않으면 build가 실행 안되는 건가요?
0
83
1
video_call 플러그인 설치시 에러문제
0
105
1
children 안의 if 문에서 { } 못쓰는 이유?
0
77
1
이렇게 오류가 떠요
0
120
1
AppBar 사용했는데
0
103
2
[문제해결] '오늘도 출첵!' 의 171번 강의에서 중요한 문제를 발견했습니다
0
79
1
StatefulWidget 실습 에러가 발생합니다.[해결완료]
0
86
1
Video Player 프로젝트에 대한 추가 질문
0
76
0
Row위젯이나 column위젯의 위치는 누가 정하나요??
0
65
1
geolocator 오류때문에 개발진행이 불가능입니다
0
94
1





