首页 > 解决方案 > Flutter:使用图像而不是图标

问题描述

我有一个无线电流播放器的示例代码。该代码提供了一个图标来表示其状态(暂停或播放)。我想显示图像而不是图标。

作为一个新手/菜鸟,我被卡住了。有人能把我推向正确的方向吗?

这是当前代码:

...........    
default:
                        return Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              IconButton(
                                  onPressed: () async {
                                    print("button press data: " +
                                        snapshot.data.toString());
                                    await _flutterRadioPlayer.playOrPause();
                                  },
                                  icon: snapshot.data ==
                                          FlutterRadioPlayer
                                              .flutter_radio_playing
                                      ? Icon(Icons.pause)
                                      : Icon(Icons.play_arrow))
                            ]);
                        break;
                    }
...............

所以简而言之,我想使用一个图像,“pause.png”用于 Icons.pause,“play.png”用于 Icons.play_arrow。

标签: imagefluttericons

解决方案


该图标是 Widget 类型,因此您可以传递例如 Image.asset([path to asset]) 而不是 Icon()


推荐阅读