Flutter初学之路—`Icon` (图标组件)
2019-04-26 本文已影响5人
白晓明
Icon(图标组件)为展示图标的组件。其提供了一种构造器。
const Icon(IconData icon, {//显示的图标
Key key,
double size,//图标尺寸
Color color, //图标颜色
String semanticLabel,//语义标签
TextDirection textDirection,//用户呈现图标的文本方向
})
图标是不能做交互的,若需要交互式图标,请使用material
的IconButton
。
当使用图标时,必须有一个具有方向性的组件。通常是由WidgetsApp
或MaterialApp
自动引入的。
另外
-
IconButton
:交互式图标; -
Icons
:图标列表,图标库中的图标; -
ImageIcon
:用于显示来自AssetImage
或其他ImageProviders
的图标。
继承:
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