App바 기본
1. leading : 아이콘 버튼이나 간단한 위젯을 왼쪽에 배치할 때
2. actions : 복수의 아이콘 버튼 등을 오른쪽에 배치했을 때
3. onPressed : 함수형태로 버튼이나 아이콘 터치했을 때 발생하는 이벤트를 정의하는 곳
코드
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'AppBar',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Appbar icon Menu'),
centerTitle: true,
elevation: 0.0,
leading: IconButton(
icon: Icon(Icons.menu), onPressed: () {
print('menu button is clicked');
},
),
actions: [
IconButton(
icon: Icon(Icons.shopping_cart), onPressed: () {
print('shp cart button is clicked');
},
),
IconButton(
icon: Icon(Icons.search), onPressed: () {
print('search button is clicked');
},
),
],
),
);
}
}
drawer메뉴
기본 구성
* onTab, onPressed 차이
onPressed는 버튼에 주로 사용
onTab은 gestureDetector, InkWell 같은데 주로 사용
- 길게 누르기, 두번 탭하기 등 액션 감지 가능
drawer코드
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'AppBar',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Appbar icon Menu'),
centerTitle: true,
elevation: 0.0,
actions: [
IconButton(
icon: Icon(Icons.shopping_cart), onPressed: () {
print('shp cart button is clicked');
},
),
IconButton(
icon: Icon(Icons.search), onPressed: () {
print('search button is clicked');
},
),
],
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
currentAccountPicture: CircleAvatar(
backgroundImage: AssetImage('1.png'),
backgroundColor: Colors.white,
),
otherAccountsPictures: [
CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: AssetImage('1.png'),
),
// CircleAvatar(
// backgroundColor: Colors.white,
// backgroundImage: AssetImage('1.png'),
// ),
],
accountName: Text('changPa'),
accountEmail: Text('changPa@chang.com'),
onDetailsPressed: (){
print('arrow is clicked');
},
decoration: BoxDecoration(
color: Colors.red[200],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(20.0),
bottomRight: Radius.circular(20.0),
)
),
),
ListTile(
leading: Icon(Icons.home,
color: Colors.grey[850]),
title: Text('Home'),
onTap: (){
print('Home is clicked');
},
trailing: Icon(Icons.add),
),
ListTile(
leading: Icon(Icons.settings,
color: Colors.grey[850]),
title: Text('Settings'),
onTap: (){
print('Settings is clicked');
},
trailing: Icon(Icons.add),
),
ListTile(
leading: Icon(Icons.question_answer,
color: Colors.grey[850]),
title: Text('Q&A'),
onTap: (){
print('Q&A is clicked');
},
trailing: Icon(Icons.add),
),
],
),
),
);
}
}
'플로터(Flutter) > 기본' 카테고리의 다른 글
(코딩쉐프) 19강 Toast Message (0) | 2023.01.03 |
---|---|
(코딩쉐프) 17~18강 BuildContext, Snack bar (0) | 2022.12.29 |
(코딩쉐프) Null Safety (0) | 2022.12.28 |
(코딩쉐프) 순한맛 11강 [캐릭터 페이지 완성] (0) | 2022.12.28 |
(코딩쉐프) 순한맛 11강 이미지 처리 (0) | 2022.12.28 |