0

I have a sample code for a radiostream player. The code provides for an icon to represent its state (paused or playing). I would like to show an image instead of the icon.

Being a newby/noob with flutter im stuck. Can sonebody push me in the right direction?

Here is the current code:

...........    
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;
                    }
...............

So in short, i want to use an image, "pause.png" for Icons.pause and "play.png" for Icons.play_arrow.

3 Answers 3

1

Remove that IconButton thing and use this as a child of Future Builder and the future builder will return this

Image.asset('pause.png'):Image.asset('play.png')
Sign up to request clarification or add additional context in comments.

Comments

1

the icon is of type Widget so you can pass for example Image.asset([path to asset]) instead Icon()

Comments

1

here is the example

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;
                    }



Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.