When I set the color of a Container that holds an IconButton, I find that highlight color of the IconButton is hidden by the color of the container. Here's what I mean:
How can ensure that the blue circle appears above the red square?
Here's my code:
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new MyDemo()));
}
class MyDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Container(
width: 60.0,
height: 60.0,
color: Colors.red,
child: new IconButton(
highlightColor: Colors.blue,
icon: new Icon(Icons.add_a_photo), onPressed: ()=>{},),
),
),
);
}
}
Steps to change icon button color in FlutterLocate the file where you have placed the IconButton widget. Inside the IconButton widget, add the color parameter and assign the color of your choice. Run the App.
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 to Make Icon Clickable in Flutter? You can wrap Icon() widget with InkWell or alternatively GestureDetector() widget to make icons clickable in your Flutter app.
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.
InkSplash occurs on the closest ancestor Material
widget.
You can get that widget using Material.of(context)
which provides a few helpers for InkSplashes.
In your case, it's InkResponse
instantiated by IconButton
which provoke the Splash effect.
But the targeted Material
widget is instantiated by Scaffold
. Which is an ancestor of your background. Therefore the background paints above your InkSplash.
To solve this problem you'd have to introduce a new Material
instance between your background and your IconButton
.
Which leads to :
Guh, we solved the problem. But now it's cropped ! Let's continue.
The easiest option would be to split your rendering in two branches. One for the background, and one for the UI. Something similar should do the trick :
return new Scaffold(
body: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Center(
child: new Container(
height: 60.0,
width: 60.0,
color: Colors.red,
),
),
new Material(
type: MaterialType.transparency,
child: new IconButton(
highlightColor: Colors.blue,
icon: new Icon(Icons.add_a_photo),
onPressed: () => {},
),
),
],
),
);
Try this
Material(
color: Colors.transparent,
shape: CircleBorder(),
clipBehavior: Clip.hardEdge,
child: IconButton(
icon: Icon(Icons.arrow_back),
iconSize: 30,
color: Colors.white,
onPressed: () {
},
),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With