반응형
이 코드는 어느정도 플러터를 아는 사람이, 새 프로젝트를 만들때 사용하라고 만든 기본코드다.
버튼, title, onPressed와 Snackbar등을 구현해 두었다.
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
|
import 'package:flutter/material.dart'; //flutter의 package를 가져오는 코드 반드시 필요
void main() => runApp(MyApp()); //main에서 MyApp이란 클래스를 호출한다.
class MyApp extends StatelessWidget {
//MyApp 클래스 선언
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'my first app',
home: MyPage(),
);
}
}
class MyPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
elevation: 0,
centerTitle: true,
title: Text("hello world"),
leading: IconButton(icon: Icon(Icons.menu), onPressed: () {}),
actions: [
IconButton(icon: Icon(Icons.image), onPressed: () {}),
IconButton(icon: Icon(Icons.search), onPressed: () {}),
],
),
body: Center(
child: Column(
children: [
SizedBox(height: 50),
ElevatedButton(onPressed: (){showSnackBar(context);}, child: Text("elevated Button")),
],
),
),
);
}
}
void showSnackBar(BuildContext context){
ScaffoldMessenger.of(context).showSnackBar(
//SnackBar 구현하는법 context는 위에 BuildContext에 있는 객체를 그대로 가져오면 됨.
SnackBar(
content: Text('snackbar'),
//snack bar의 내용. icon, button같은것도 가능하다.
duration: Duration(seconds: 5), //올라와있는 시간
)
);
}
|
cs |
다음과 같은 화면이 나오게 된다. 새 프로젝트를 시작할때 이걸 복사하고 시작하면 시간을 단축할 수 있을 것이다.
다음에는 Stateful용 기본코드를 만들어 보겠다.
반응형
'Flutter' 카테고리의 다른 글
flutter expanded 사용법 (0) | 2021.09.07 |
---|---|
flutter alligment 사용법 (0) | 2021.09.05 |
flutter DateTime사용법 (0) | 2021.09.01 |
Flutter firestore database 존재성, 데이터 가져오기 (0) | 2021.08.30 |
Flutter Firestore database 사용법 (0) | 2021.08.28 |