っ碎片化代码Flutter圈子Flutter

Flutter初学之路—`Icon` (图标组件)

2019-04-26  本文已影响5人  白晓明

Icon(图标组件)为展示图标的组件。其提供了一种构造器。

  const Icon(IconData icon, {//显示的图标
    Key key,
    double size,//图标尺寸
    Color color,    //图标颜色
    String semanticLabel,//语义标签
    TextDirection textDirection,//用户呈现图标的文本方向
  })
图标是不能做交互的,若需要交互式图标,请使用materialIconButton

当使用图标时,必须有一个具有方向性的组件。通常是由WidgetsAppMaterialApp自动引入的。

另外

继承:

Object > Diagnosticable > DiagnosticableTree > Widget > StatelessWidget > Icon

属性:

名称 类型 说明
color Color 图标颜色
icon IconData 显示的图标
semanticLabel String 语义标签,此标签不会显示在UI中
size double 图标尺寸
textDirection TextDirection 用户呈现图标的文本方向

示例:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    const data = "Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep";
    return MaterialApp(
      title: 'Hello World!',
      theme: ThemeData(
        primaryColor: Colors.red,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Fultter'),
        ),
        body: Center(
          child: Icon(
            Icons.build,
            color: Colors.red,
            semanticLabel: "user",
            size: 64.0,
            textDirection: TextDirection.rtl,
          ),
        ),
      ),
    );
  }
}

参考文档:Icon class

上一篇 下一篇

猜你喜欢

热点阅读