stless라고 작성 후 Tab 키 누르면 위젯을 상속한 class가 생성됨 → 클래스 이름 작성해주기import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
Widget build(BuildContext context) {
return MaterialApp(
);
}
}
⇒ MaterialApp()을 사용하면 구글에서 제공하는 디자인을 사용할 수 있다.
flutter:
uses-material-design: true
⇒ Cupertino~()를 사용하면 아이폰 관련 위젯 사용 가능하다.
MaterialApp(
home: Text('안녕')
)

Colors.색
Color(0xffffffff) → 꼭 rgb 삽입 전 0xff를 넣어야 함
Color.fromRGBO()
Text( '글자임',
style : TextStyle( color : Colors.red )
)
MaterialApp(
home: Icon(Icons.star)
)

flutter:
assets:
- assets/MaterialApp(
home: Image.asset('assets/dog.png')
)

// 크기 지정을 안해줘서 화면에서 안보임
MaterialApp(
home: Container()
)
// 폭, 높이, 색상 적용 -> 컴퓨터가 박스를 어디서부터 가로세로를 그려야할지 모르기 때문에 안보임
MaterialApp(
home: Container(width : 50, height : 50, color: Colors.blue)
)
// 좌표를 찍어줘야 폭, 높이, 색상이 적용됨
MaterialApp(
home: Center(
child: Container(width : 50, height : 50, color: Colors.blue)
)
)

margin: EdgeInsets.all(20) or EdgeInsets.fromLTRB(0, 0, 0, 0)
padding: EdgeInsets.all(20) or EdgeInsets.fromLTRB(0, 0, 0, 0)
margin: EdgeInsets.all(30),
padding: EdgeInsets.fromLTRB(10, 20, 30, 40),
박스 테두리, 그림자, 박스 둥글게 등등 가능
decoration: BoxDecoration( border: Border.all(color: Colors.black))
만약 decoration을 사용하는 경우엔 Container() 의 색을 지정해주고 싶은 경우 decoration 안에 지정해줘야 함
- color, shape, boxShadow, gradient, image, borderRadius 등
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('앱임')),
body: Container(
width: 50, height: 50,
decoration: BoxDecoration(
border: Border.all(color: Colors.black)
),
),
)
)
// 이건 불가능 -> 에러 뜸
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('앱임')),
body: Container(
width: 50, height: 50, color: Colors.blue,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.black)
),
),
)
)
중앙 정렬
- Center()로 Container() 감싸기
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('앱임')),
body: Center(
child: Container(
width: 50, height: 50, color: Colors.blue,
),
),
)
)
그외 정렬
- Align()으로 Container() 감싸고 그 윗 줄에 alignmemt: Alignment.정렬방법 해주면 됨
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('앱임')),
body: Align (
alignment: Alignment.bottomCenter,
child: Container(
width: 50, height: 50, color: Colors.blue,
),
),
)
)
double.infinty 해주면 됨
Container( width : double.infinity, height : 50, color : Colors.blue )


TextButton( child: Text('글자'), onPressed: (){} )

IconButton( icon: Icon(), onPressed: (){} )

ElevatedButton( child: Text('글자'), onPressed: (){} )
Row(
children : [
Flexible( child: Container(color : Colors.blue), flex : 1 ),
Flexible( child: Container(Color : Colors.green), flex : 1 )
]
)
TextField 양옆에 아이콘 넣고 싶으면 icon: 파라미터

TextField(
decoration: InputDecoration(
icon: Icon(Icons.star),
),
),
border 주려면 enabledBorder: 파라미터

TextField(
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.green,
width: 1.0,
),
),
),
)
TextField(
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(),
),
),테두리 둥글게 하고 싶으면 borderRadius :

TextField(
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
border 없애기 & 배경색 입히기

TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.blue.shade100,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide.none,
)
),
),
힌트 띄우기

TextField(
decoration: InputDecoration(
hintText: 'hint',
helperText: 'helper',
labelText: 'label',
counterText: 'counter'
),
),