Flutter 中使用 ICON

Flutter Icon URL : https://fonts.google.com/icons

在Flutter中使用 Icon 步骤如下:

导入图标库

在Dart 文件中导入 material.dart 包,该包包含了 Flutter 的图标库。

dart 复制代码
import 'package:flutter/material.dart';

使用图标组件

通过 Icon 来创建图标组件,Icon 组件接受一个 IconData 对象作为参数,用于指定要显示的具体图标。

具体图标可以去 该网站找,然后复制对应的 Icon name 即可。

Icon 参数:如下

dart 复制代码
Icon(
  IconData? icon, {
  Key? key,
  double? size,
  double? fill,
  double? weight,
  double? grade,
  double? opticalSize,
  Color? color,
  List<Shadow>? shadows,
  String? semanticLabel,
  TextDirection? textDirection,
})
  • color:设置图标的颜色。
  • size:设置图标的大小。
  • semanticLabel:设置图标的语义标签,用于辅助功能。

完整示例:

dart 复制代码
Icon(
  Icons.favorite, // 使用预定义的图标名称
  size: 30.0, // 设置图标大小为 30.0 像素
  semanticLabel: 'Accessibility', // 设置语义标签为 "Accessibility"
  textDirection: TextDirection.rtl, // 设置文本方向为从右到左
)

使用示例:

dart 复制代码
Row(
    children: [
      Container(
        width: 80.0,
        child:Column(
        children: [
          Icon(
            Icons.favorite,
            color: Colors.red,
            size: 24.0,
            semanticLabel: 'Favorite',
          ),
          Text("Love",
          style: TextStyle(
            fontSize: 17,
            color:Colors.green,
          )),
        ],
      ),
      ),
      Container(
        width: 80.0,
        child:Column(
        children: [
          Icon(
            Icons.android_outlined,
            color: Color.fromARGB(255, 18, 161, 238),
            size: 24.0,
            semanticLabel: 'Favorite',
          ),
          Text("Android",
          style: TextStyle(
            fontSize: 17,
            color:Colors.green,
          )),
        ],
      ),
      ),
      Container(
        width: 80,
        child:Column(
        children: [
          Icon(
            Icons.verified_outlined,
            color: Color.fromARGB(255, 9, 232, 69),
            size: 24.0,
            semanticLabel: 'Favorite',
          ),
          Text("Verified",
          style: TextStyle(
            fontSize: 17,
            color:Colors.green,
          )),
        ],
      ),
      ),
    ],
  ),
相关推荐
饭小猿人7 小时前
Flutter实现底部动画弹窗有两种方式
开发语言·前端·flutter
liulian091611 小时前
Flutter 跨平台路由与状态管理:go_router 与 Riverpod 的 OpenHarmony总结
flutter·华为·学习方法·harmonyos
liulian091612 小时前
Flutter for OpenHarmony 跨平台技术实战:flutter_animate 与 pull_to_refresh 库的鸿蒙化适配总结
flutter·华为·学习方法·harmonyos
IntMainJhy12 小时前
【flutter for open harmony】第三方库 Flutter 二维码生成的鸿蒙化适配与实战指南
数据库·flutter·华为·sqlite·harmonyos
jiejiejiejie_13 小时前
Flutter for OpenHarmony 底部选项卡与多语言适配小记:让 App 更贴心的两次小升级✨
flutter·华为·harmonyos
jiejiejiejie_14 小时前
Flutter for OpenHarmony 应用更新检测与萌系搜索功能实战小记✨
flutter·华为·harmonyos
IntMainJhy14 小时前
Flutter 三方库 Firebase Messaging 鸿蒙化适配与实战指南(权限检查+设备Token获取全覆盖)
flutter·华为·harmonyos
liulian091616 小时前
Flutter 依赖注入与设备信息库:get_it 与 device_info_plus 的 OpenHarmony 适配指南总结
flutter·华为·学习方法·harmonyos
里欧跑得慢16 小时前
微交互设计模式:提升用户体验的细节之美
前端·css·flutter·web
stringwu16 小时前
Flutter GetX 核心坑及架构选型与可替换性方案
前端·flutter