Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add tintColor on my IconButton in Flutter?

I want to put a tintColor on my IconButton(upper right corner) so I don't have to put same image of different colors in my project.

How do you do tintColor in Flutter?

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          resizeToAvoidBottomPadding: true,
          backgroundColor: SILVER,
          appBar: AppBar(
            title: Text(
            APP_NAME,
            style: TextStyle(
              color: RED,
              fontFamily: 'Allan')),

          // Action buttons
          actions: < Widget > [
            Container(
              width: 45,
              child: 
                IconButton(
                  color: BLACK,
                  icon: Image.asset("assets/images/ic_planet.png"),
                  tooltip: "Planets",
                  onPressed: () {
                    _handleSelectedAction();
                  },   
            )
          ...
      )
    ],

Here's what the icon looks like on the upper right corner

like image 869
Anton Avatar asked Jan 27 '19 14:01

Anton


People also ask

How do you change the color of a PNG icon on Flutter?

Here's how you do it: Step 1: Locate the MaterialApp widget. Step 2: Inside the MaterialApp, add the theme parameter with ThemeData class assigned. Step 3: Inside the ThemeData add the iconTheme parameter and then assign the IconThemeData . Step 4:Inside the IconThemeData add the color parameter and set its color.

How do I add an IconButton in Flutter?

The simplest way to create a button with icon and text in Flutter is to use the new Material button called ElevatedButton with an icon constructor. ElevatedButton. icon() gives you the ability to add the icon and label parameter to the button. The ElevatedButton was introduced with the release of Flutter v1.

How do you add an Assetimage in Flutter?

Steps to Add Image in Flutter (Local Image) To add image in Flutter app, first of all, create an assets/images folder then add the actual images inside the folder. After this, Add the image path in pubspec. yaml and then display it using the Image. asset() widget.

How do I change my icon onPressed Flutter?

Just wrap the logic around setState(){} in onPressed() of floatingActionButton. When on click on the FloatingActionButton with Refresh Icon, the icon is changed to Stop.


Video Answer


1 Answers

If you mean the actual icon color, you can set that on the Image.asset constructor:

Image.asset(..., color: Colors.orange)

Icons have it too:

Icon(..., color: Colors.orange)

For some reason it's not working for me to set the color directly on the IconButton.

like image 193
Edman Avatar answered Oct 27 '22 11:10

Edman