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,
          )),
        ],
      ),
      ),
    ],
  ),
相关推荐
Cao_Shixin攻城狮5 小时前
Flutter运行Android项目时显示java版本不兼容(Unsupported class file major version 65)的处理
android·java·flutter
人生游戏牛马NPC1号13 小时前
学习 Flutter (四):玩安卓项目实战 - 中
android·学习·flutter
YueYaTech16 小时前
【Flutter 必备插件】屏幕适配方案 flutter_screenutil
flutter
耳東陈17 小时前
【重磅发布】Flutter 生态首个可商用 K线图表库flutter_chen_kchart
flutter
程序员老刘18 小时前
AI智能体正在颠覆App开发,不转型就淘汰
flutter·客户端·mcp
worxfr19 小时前
Flutter 入门指南:从基础到实战
flutter
yuanlaile19 小时前
Flutter Android打包学习指南
android·flutter·flutter打包·flutter android
0wioiw021 小时前
Flutter基础(前端教程①①-底部导航栏)
flutter
sunly_1 天前
Flutter:上传图片,选择相机或相册:wechat_assets_picker
数码相机·flutter·微信
_Shirley1 天前
安卓开发使用Android Studio配置flutter环境
android·flutter·android studio