Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

개발부터 자유까지

[Flutter] 코딩쉐프 순한맛 강좌 14 - 메뉴 아이콘 추가하기 본문

Flutter

[Flutter] 코딩쉐프 순한맛 강좌 14 - 메뉴 아이콘 추가하기

건물주개발자 2024. 9. 8. 00:10

 

AppBar 위젯에서 사용하는 속성

  • leading : 아이콘 버튼이나 간단한 위젯을 왼쪽에 배치할 때
  • actions : 복수의 아이콘 버튼 등을 오른쪽에 배치할 때
  • onPressed : 함수의 형태로 일반 버튼이나 아이콘 버튼을 터치했을 때 일어나는 이벤트를 정의

 

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: 'AppBar',
      theme: ThemeData(
        primarySwatch: Colors.red
      ),
      home: const MyPage(),
    );
  }
}

class MyPage extends StatelessWidget {
  const MyPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Appbar icon menu'),
        centerTitle: true,
        elevation: 0.0,
        leading: IconButton(
            onPressed: (){
              print("menu button is clicked");
            },
            icon: Icon(Icons.menu)
        ),
        actions: [
          IconButton(
              onPressed: (){
                print("shopping cart button is clicked");
              },
              icon: Icon(Icons.shopping_cart)
          ),
          IconButton(
              onPressed: (){
                print("Search button is clicked");
              },
              icon: Icon(Icons.search)
          ),
        ],
      ),
    );
  }
}

 

 

https://youtu.be/ze0t5gWKBvE?si=lCwLNd_YqqjWhuTt