Flutter 的 Icon widget 可用來顯示 icon。

其建構子如下:

Icon(IconData icon, { Key key, double size, Color color, String semanticLabel, TextDirection textDirection })

屬性如下:

NameTypeDescription
colorColorThe color to use when drawing the icon.
iconIconDataThe icon to display. The available icons are described in Icons.
semanticLabelStringSemantic label for the icon.
sizedoubleThe size of the icon in logical pixels.
textDirectionTextDirectionThe text direction to use for rendering the icon.
hashCodeintThe hash code for this object.
keyKeyControls how one widget replaces another widget in the tree.
runtimeTypeTypeA representation of the runtime type of the object.

方法如下:

NameReturn TypeDescription
build(BuildContext context)WidgetDescribes the part of the user interface represented by this widget.
debugFillProperties(DiagnosticPropertiesBuilder description)void
createElement()StatelessElementCreates a StatelessElement to manage this widget’s location in the tree.
debugDescribeChildren()ListReturns a list of DiagnosticsNode objects describing this node’s children.
noSuchMethod(Invocation invocation)dynamicInvoked when a non-existent method or property is accessed.
toDiagnosticsNode({String name, DiagnosticsTreeStyle style })DiagnosticsNodeReturns a debug representation of the object that is used by debugging tools and by toStringDeep.
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this object.
toStringDeep({String prefixLineOne: ‘’, String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this node and its descendants.
toStringShallow({String joiner: ‘, ‘, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a one-line detailed description of the object.
toStringShort()StringA short, textual description of this widget.

Icon 元件需在 MaterialApp 下使用,所以會要建立 MaterialApp,然後將 Icon 元件塞給 MaterialApp 的 home 屬性。

Icon 元件建立時需要指定要顯示的 Icon,可直接用 Icons 指定內建的 Icon。

其它屬性像是 color 屬性可設定 Icon 的顏色。

import 'package:flutter/material.dart';

void main() {
runApp(
new MaterialApp
(
home: new Icon
(
Icons.flag,
color: Colors.white,
)
)
);
}

1.png

2.png

或是 size 屬性可設定 Icon 的大小。

import 'package:flutter/material.dart';

void main() {
runApp(
new MaterialApp
(
home: new Icon
(
Icons.flag,
color: Colors.white,
size: 100.0,
)
)
);
}

3.png

4.png