반응형
많은 분들에게 기본적인 도움이라도 되길 바라며, 학습 목적 외에 상업적 이용은 금합니다.
출처: 패스트캠퍼스 15개 프로젝트로 실무까지 끝내는 Dart & Fultter 앱 개발, 챗 gpt
출처: https://forfire700.tistory.com/149 [IT STUDY CAFE:티스토리]
tip: column 행을 의미하며, row는 열을 의미한다. 그리고 Axis(행 또는 열의 이동방향과 수평한 방향 ㅣ,ㅣ ㅡ,ㅡ), Cross(행 또는 열의 이동방향과 수직한 방향 ㅣ,ㅡ ㅡ,ㅣ)을 의미합니다.
상하
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('widget을 상하로 배치하기'), centerTitle: true, ), body: Body(), ), ), ); } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { return Container( width: double.infinity, child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: 100, height: 80, color: Colors.red, child: Text('Container 1')), Container( width: 100, height: 80, color: Colors.green, child: Text('Container 2')), Container( width: 100, height: 80, color: Colors.blue, child: Text('Container 3')), ], ), ); } } | cs |
좌우
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('widget을 좌우로 배치하기'), centerTitle: true, ), body: Body(), ), ), ); } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { return Container( height: double.infinity, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: 100, height: 80, color: Colors.red, child: Text('Container 1')), Container( width: 100, height: 80, color: Colors.green, child: Text('Container 2')), Container( width: 100, height: 80, color: Colors.blue, child: Text('Container 3')), ], ), ); } } | cs |
상화좌우
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('widget을 상하좌우로 배치하기'), centerTitle: true, ), body: Body(), ), ), ); } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { return Container( width: double.infinity, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.end, children: [ Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.end, children: [ Container( width: 100, height: 80, color: Colors.red, child: Text('Container 1')), Container( width: 100, height: 80, color: Colors.green, child: Text('Container 2')), Container( width: 100, height: 80, color: Colors.blue, child: Text('Container 3')), ], ), Container( width: 300, height: 120, child: Text('Container 4'), color: Colors.grey, ) ], ), ); } } | cs |
가로 스크롤 바(수직 스크롤 바는 여기서 조금만 수정하시면 되는데, 한번 도전해보시면 좋습니다.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('widget을 상하좌우로 배치하기'), centerTitle: true, ), body: Body(), ), ), ); } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { return SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.end, children: [ Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ),Container( color: Colors.grey, width: 100, height: 100, margin: EdgeInsets.symmetric(horizontal: 8), ), ], ), ); } } | cs |
반응형
'It Study > 앱 개발 실습 기록(Flutter)' 카테고리의 다른 글
플러터 - 체크박스 위젯, 상업적 이용 x (오류 수정 및 주석) (0) | 2024.08.03 |
---|---|
플러터 기본 위젯 예제(MaterialWidget) - 위젯 비율 배치 및 스크롤바 테스트 (0) | 2024.07.30 |
플러터 기본 위젯 예제(MaterialWidget) - container 실습 (2) | 2024.07.24 |
플러터 기본 위젯 예제(MaterialWidget) - appBar, IconButton, floatingActionButton (2) | 2024.07.23 |
플러터 기본 위젯 예제(MaterialWidget) (0) | 2024.07.21 |