-
앱 개발 입문 수강 기록 5일 차_2023-02-24Study 2023. 2. 24. 23:31
강좌명
CH01_06. 여러 위젯 같이 써보기 (가로, 세로로 다양한 위젯 배치)
- Row, Column, ListView, ListTile
- Row
- 가로로 여러 위젯을 배치할 때 사용하는 위젯
- Column
- 세로로 여러 위젯을 배치할 때 사용하는 위젯
- Expanded
- Column, Row 위젯 안에서 영역을 전체로 확장할 때 사용하는 위젯
- ListView
- 여러 위젯을 나열할 때 사용하는 위젯
- Column과 Row와는 달리 스크롤이 가능한 위젯
- 스크롤 방향을 설정할 수 있음
- ListTile
- ListView에서 사용하는 기본 위젯
- GridView
- 여러 위젯을 나열할 때 사용하는 위젯
- Column과 Row를 포함한 스크롤 가능한 위젯
- 휴대폰 갤러리 UI와 같은 Grid Layout 위젯
- Row
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; int _idx = 0; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("패스트캠퍼스 테스트"), ), body: Center( child: GridView.count( crossAxisCount: 2, childAspectRatio: 1, children: <Widget>[ Text("이름"), Text("이름"), Text("이름"), ListTile( title: Text("이름"), trailing: Text("ntts"), onTap: () { print("ntts9990"); }, ) ], ), ), ); } }
- InkWell, GestureDetector
- InkWell
- 위젯을 클릭 가능하도록 만드는 위젯
- GestureDetector
- 위젯을 클릭 가능하도록 만드는 위젯
- 클릭(onTap), 길게 클릭(onLongPress) 사용 가능
- 버튼이 아닌 다른 위젯을 클릭 가능하도록 감싸는 위젯
- InkWell
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; int _idx = 0; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("패스트캠퍼스 테스트"), ), body: Center( child: GridView.count( crossAxisCount: 2, childAspectRatio: 1, children: <Widget>[ InkWell(child: Text("클릭되는 모션 있음"), onTap: (){ print("InkWell 클릭됨"); }, ), GestureDetector(child: Text("클릭되는 모션 없음"), onTap: (){ print("GestureDetector 클릭됨"); }, ), Text("이름"), Text("이름"), Text("이름"), ListTile( title: Text("이름"), trailing: Text("ntts"), onTap: () { print("ntts9990"); }, ) ], ), ), ); } }
- margin, padding
- Margin
- 위젯 외부 여백
- Padding
- 위젯 내부 여백
- EdgeInsets
- 여백 추가 위젯
- Margin
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; int _idx = 0; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("패스트캠퍼스 테스트"), ), body: Center( child: GridView.count( crossAxisCount: 2, childAspectRatio: 1, children: <Widget>[ Container(child: Text("이름"), margin: EdgeInsets.all(16), padding: EdgeInsets.all(16), color: Colors.blueGrey, ), Text("이름"), Text("이름"), Text("이름"), ListTile( title: Text("이름"), trailing: Text("ntts"), onTap: () { print("ntts9990"); }, ) ], ), ), ); } }
- 정리
- 괄호들 맞추는 게 어려웠...지만 Android Studio에서 Expected to find '}' 등으로 알려줘서 편해졌다.
- 들여쓰기도 자동으로 해주고 주석(실제 작성한 건 아니고 표시만 되어 있음)도 자동으로 달아줘서 다행이야...
- 괄호들 맞추는 게 어려웠...지만 Android Studio에서 Expected to find '}' 등으로 알려줘서 편해졌다.
#패스트캠퍼스 #패캠챌린지 #수강료0원챌린지
#직장인인강 #직장인자기계발 #패캠인강후기 #패스트캠퍼스후기
#환급챌린지 #오공완 #누적다운로드120만1인개발자와함께하는앱개발입문Online
http://bit.ly/3Y34pE0본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.
'Study' 카테고리의 다른 글
앱 개발 입문 수강 기록 7일 차_2023-02-26 (0) 2023.02.26 앱 개발 입문 수강 기록 6일 차_2023-02-25 (0) 2023.02.25 앱 개발 입문 수강 기록 4일 차_2023-02-23 (0) 2023.02.23 앱 개발 입문 수강 기록 3일 차_2023-02-22 (0) 2023.02.22 앱 개발 입문 수강 기록 2일 차_2023-02-21 (0) 2023.02.21 - Row, Column, ListView, ListTile