Flutter

플러터 - 아이콘

마루설아 2025. 4. 8. 19:50
...
dependencies:
  flutter:
    sdk: flutter
    
  font_awesome_flutter: ^10.1.0 // 폰트 어섬 아이콘 사용
 ...

 

pubspec.yaml

폰트 어섬 사용을 위한 의존성 추가

 

 

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; // 폰트어섬 패키지

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // 버튼 누를때 onPressed 함수 호출
  onPressed() {
    print("Icon Clicked!");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('TEST')),

        body: Column(
          children: [
            // 플러터의 기본 아이콘 사용하기
            Icon(Icons.alarm, size: 100, color: Colors.red),

            // 폰트어섬의 아이콘 사용하기
            FaIcon(FontAwesomeIcons.bell, size: 100),

            // 아이콘 버튼 사용하기
            IconButton(
              onPressed: onPressed, // 클릭할 때 onPressed 호출
              icon: Icon(Icons.alarm, size: 100),
            ),
          ],
        ),
      ),
    );
  }
}

 

 

 

 

 

 

가장 아래 아이콘 버튼 클릭 시 로그 출력 확인