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,
          )),
        ],
      ),
      ),
    ],
  ),
相关推荐
神奇的程序员6 小时前
开发了一个管理本地开发环境的软件
前端·flutter
xmdy58667 小时前
Flutter+开源鸿蒙实战|智联邻里Day9 系统权限适配+应用全局分享+缓存深度优化+版本更新弹窗
flutter·开源·harmonyos
maaath12 小时前
【maaath】Flutter for OpenHarmony 乐器学习应用开发实战
flutter·华为·harmonyos
maaath17 小时前
【maaath】 Flutter for OpenHarmony 实战:电池优化应用开发指南
flutter·华为·harmonyos
勤劳打代码18 小时前
Flutter 架构日记 —— 可演进的 Flutter Dialog 组件
flutter·架构
Eric_HYD21 小时前
Flutter 字体字生效原理解析
flutter
maaath21 小时前
【无标题】Flutter for OpenHarmony 的文具手账应用开发实践
flutter·华为·harmonyos
里欧跑得慢21 小时前
Flutter 主题管理:构建一致的用户界面
前端·css·flutter·web
liulian09161 天前
Flutter for OpenHarmony 跨平台开发:单位转换功能实战指南
flutter
千码君20162 天前
Trae:一些关于flutter和 go前后端开发构建的分享
android·flutter·gradle·android-studio·trae·vibe code