플러터에서 Drawer사용 방법은 매우 간단합니다. 아래 이미지와 같이 만들기 위해서 Drawer을 생성하고 ListView위젯을 생성한 후 UserAccountsDrawerHeader위젯과 ListTile위젯을 생성하면 됩니다. 우측 이미지를 보면 상단 핑크색이 UserAccountsDrawerHeader위젯이고 하단 Home, Q&A, Settings가 ListTile입니다.
▣ Drawer위젯 만드는 순서
- Drawer위젯 생성
- ListView위젯 생성
- UserAccountsDrawerHeader위젯 생성
- ListTile위젯 생성
▣ 코드
drawer: Drawer(
// 드로월위젯
child: ListView(
// 리스트뷰위젯
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
// 리스트뷰위젯의 헤더
accountName: Text("homg"),
// 헤더 이름
accountEmail: Text('bbb@naver.com'),
// 헤더 이메일주소
currentAccountPicture: CircleAvatar(
// 헤더 이미지
backgroundImage: AssetImage('lalee.png'),
),
otherAccountsPictures: [
// 헤더 우측 추가 이미지
CircleAvatar(
backgroundImage: AssetImage('pika.png'),
),
CircleAvatar(
backgroundImage: AssetImage('pika.png'),
),
],
onDetailsPressed: () {},
// 헤더 하단 버튼
decoration: BoxDecoration(
// 헤더 꾸미기
color: Colors.red[200],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
)),
),
ListTile(
leading: Icon(
// 좌측 위젯
Icons.home,
color: Colors.grey[850],
),
title: Text('Home'),
onTap: () {
print('Home');
},
trailing: Icon(
Icons.add,
), // 우측 위젯
),
ListTile(
leading: Icon(
// 좌측 위젯
Icons.question_answer,
color: Colors.grey[850],
),
title: Text('Q&A'),
onTap: () {
print('Q&A');
},
trailing: Icon(
Icons.add,
), // 우측 위젯
),
ListTile(
leading: Icon(
// 좌측 위젯
Icons.settings,
color: Colors.grey[850],
),
title: Text('Settings'),
onTap: () {
print('Settings');
},
trailing: Icon(
Icons.add,
), // 우측 위젯
),
],
),
),
'개발관련 > flutter' 카테고리의 다른 글
[flutter]플러터 스낵바안에 버튼 만들기 (0) | 2022.06.29 |
---|---|
[flutter] 스낵바(SnackBar) 구버전, 신버전 (0) | 2022.06.28 |
[flutter] 앱바 좌측, 우측에 아이콘 및 아이콘버튼 생성하기 (0) | 2022.06.27 |
[flutter]플러터 이미지 넣고(CircleAvatar) 크기 조절하기 (0) | 2022.06.27 |
[flutter]Center위젯과 Column위젯을 동시 사용할때 중앙정렬을 하고 싶을 때 (0) | 2022.06.27 |
댓글