Flutter:使用图像而不是图标

Flutter: Using image instead of icon

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

作为一个 newby/noob,我卡住了。 有人可以把我推向正确的方向吗?

这是当前代码:

...........    
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。

图标是 Widget 类型的,因此您可以传递 Image.asset([资产路径]) 而不是 Icon()

删除 IconButton 东西并将其用作 Future Builder 的子项 未来的建设者将 return 这个

Image.asset('pause.png'):Image.asset('play.png')

这里是例子

return Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,

                            // replace Icon button to this custom button and wrap with Inkwell 
                            children: <Widget>[
                              InkWell(
                                  onTap: () async {
                                    print("button press data: " +
                                        snapshot.data.toString());
                                    await _flutterRadioPlayer.playOrPause();
                                  },
                                  child : snapshot.data ==
                                          FlutterRadioPlayer
                                              .flutter_radio_playing
                                      ? Image.asset("image path")
                                      : Image.asset("image path "))
                            ]);
                        break;
                    }