Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background color for an icon button?

I want to apply background color for icon button but I don't see an explicit backgroundColor property for it. I want to achieve this:

enter image description here

Currently I was able to achieve till here:

enter image description here

Below is the code so far:

@override   Widget build(BuildContext context) {  return Scaffold(     resizeToAvoidBottomPadding: false,     backgroundColor: Color(0xFF13212C),     appBar: AppBar(       title: Text('Demo'),     ),     drawer: appDrawer(),     body: new Center(     child: new Column(     crossAxisAlignment: CrossAxisAlignment.stretch,  //     mainAxisAlignment: MainAxisAlignment.spaceEvenly,     children: <Widget>[       new Column(         children: <Widget>[        //   new Flexible(     new TextField(         style: new TextStyle(         color: Colors.white,       fontSize: 16.0),       cursorColor: Colors.green,       decoration: new InputDecoration(          suffixIcon: new IconButton(             icon: new Image.asset('assets/search_icon_ivory.png'),onPressed: null),        fillColor: Colors.black,         contentPadding: new EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0),         filled: true,         hintText: 'What Do You Need Help With?',         hintStyle: new TextStyle(           color: Colors.white         )     )     )       //    )     ] ), 
like image 960
Darshan Avatar asked Oct 12 '18 10:10

Darshan


People also ask

How do I add background color to icon button?

To change the icon button color on press, add a highlightColor property to the IconButton widget. Inside the highlightColor assign the color of your choice.

How do I fill a color with icon?

To change the color of an icon, select the icon you'd like to edit. The Format tab will appear. Then click Graphics Fill and select a color from the drop-down menu. To add an outline to your icon, click Shape Outline and select a color from the drop-down menu.

How do you change the color of an icon in 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 change the button color on click Flutter?

Go to your main. Inside the MaterialApp, find the ThemeData widget. Add the elevatedButtonTheme property inside and assign the ElevatedButtonThemeData(). Add the style property and change the color as you would change it for normal ElevatedButton. Place the ElevatedButton widget anywhere in your Flutter app and see.


2 Answers

You can use a Circular Avatar with the radius = text field's height/2 or whatever height you prefer.

To figure out text field specs you can visit material.io

So the chunk of code is going to be like the following:

CircleAvatar(                 radius: 30,                 backgroundColor: Color(0xff94d500),                 child: IconButton(                   icon: Icon(                     Icons.search,                     color: Colors.black,                   ),                   onPressed: () {                     ...                   },                 ),               ), 

This way you get an Icon button with background color. I hope this can help you guys.

Icon button with background

like image 195
FJCG Avatar answered Sep 20 '22 11:09

FJCG


you can wrap your IconButton with Container and use color property to achieve desire output. May Following Example help You.

 suffixIcon: Container(               color: Colors.green,               child: new IconButton(                   icon: new Icon(Icons.search,color: Colors.white,),onPressed: null),             ), 
like image 36
Viren V Varasadiya Avatar answered Sep 20 '22 11:09

Viren V Varasadiya