줄바꿈 내부 간격
Coddy Flutter 여정의 화면 크기에 맞는 레이아웃 섹션에 포함된 레슨. 30개 중 9번째.
이제 태그들이 들어가지만 서로 맞닿아 있습니다. Wrap에는 자식 요소 사이의 간격을 설정하는 두 가지 옵션이 있습니다.
Wrap(
spacing: 8,
runSpacing: 12,
children: [...],
)spacing:은 같은 줄에 있는 두 자식 요소 사이의 간격입니다. runSpacing:은 한 줄과 다음 줄 사이의 간격입니다. Wrap의 각 줄을 run이라고 부르며, 이 이름은 여기서 유래했습니다.
Wrap은 한 줄에 어떤 요소가 들어갈지 결정할 때 간격도 고려하므로, spacing이 커지면 자식 요소가 다음 줄로 내려갈 수 있습니다.
챌린지
쉬움태그 사이에 공간을 두세요:
- 같은 줄의 태그 사이에
8픽셀 - 줄 사이에
12픽셀
직접 해보기
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final tags = ['Dart', 'Flutter', 'Mobile', 'Design', 'Games', 'Web'];
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Interests')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Wrap(
children: [
for (final tag in tags)
Container(
width: 110,
height: 40,
decoration: BoxDecoration(
color: Colors.purple.shade100,
borderRadius: BorderRadius.circular(20),
),
child: Center(child: Text(tag)),
),
],
),
),
),
);
}
}
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
화면 크기에 맞는 레이아웃의 모든 레슨
직접 연습해 보세요: 온라인 Flutter 컴파일러