Fontawesome icon in Flutter - flutter

why my icon in CircleAvatar is not in centre?
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
IconButton(
icon: CircleAvatar(
child: Icon(FontAwesomeIcons.tshirt, color: Colors.white,),
radius: 60.0,
backgroundColor: Colors.cyan
),
iconSize: 50.0,
onPressed: () {
//
},
),
Text('Odzież')
],
),
I use fontawesome to add icon, but after adding icon, he is not in thecentre of the circle avatar, have anybody any solutions to this problem?

I think this is very common issue with this library.
You have to use FaIcon widget which come with the package. They also mention this issue in their documentations FAQ.
Solution :
Just Replace your icon widget with FaIcon.
CircleAvatar(
child: FaIcon(FontAwesomeIcons.tshirt, color: Colors.white,), // Icon widget changed with FaIcon
radius: 60.0,
backgroundColor: Colors.cyan
),

Replace
IconButton(
icon: CircleAvatar(
child: Icon(FontAwesomeIcons.tshirt, color: Colors.white,),
radius: 60.0,
backgroundColor: Colors.cyan
),
iconSize: 50.0,
onPressed: () {
//
},
),
with
GestureDetector(
behavior: HitTestBehavior.translucent,
child: CircleAvatar(
child: Icon(FontAwesomeIcons.tshirt, color: Colors.white,),
radius: 60.0,
backgroundColor: Colors.cyan
),
iconSize: 50.0,
onTap: () {
//
},
),
This might help as a workaround .

Related

How to customize SlidableAction to look like a round button in flutter?

I was able to add rounded corners but could not figure out how to reduce the default padding and make it a round button.
SlidableAction(
onPressed: (context) {
// do something
},
autoClose: true, // I need this functionality
icon: FeatherIcons.copy,
),
Current Output (SlidableAction)
Required Output(Container in Slidable children)
There's multiple ways to achieve that
You can use the shape: CircleBorder()
MaterialButton(
onPressed: () {},
color: Colors.blue,
textColor: Colors.white,
child: Icon(
Icons.camera_alt,
size: 24,
),
padding: EdgeInsets.all(16),
shape: CircleBorder(),
)
OR
You can use circle avatar
CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.add),
color: Colors.white,
onPressed: () {},
),
),
You could try and use ElevatedButton instead of Slidable Action , I will share example code
ActionPane(
motion: ScrollMotion(),
children: [
Builder(
builder: (cont) {
return ElevatedButton(
onPressed: () {
Slidable.of(cont)!.close();
},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
backgroundColor: Colors.red,
padding: EdgeInsets.all(10),
),
child: const Icon(
Icons.delete,
color: Colors.white,
size: 25,
),
);
},
),
],
),

How to CENTER IconButton in CircleAvatar with Stack Widget

So here's the situation. I want to build a Spotify-like button where the circular avatar is shown and on top of that, an icon button is been placed. I want to make the icon as much bigger to cover the whole avatar as possible but have failed after trying several answers already from this platform.
So, here's what I want. Center the IconButton in the avatar covering the whole size of the Circular Avatar. I'm attaching some screenshots as well as code. Have a look at it.
Thanks!
HERE's THE CODE
import 'package:flutter/material.dart';
class AddArtistWidget extends StatelessWidget {
const AddArtistWidget({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: [
const CircleAvatar(
backgroundColor: Colors.black26,
radius: 70,
),
IconButton(
padding: EdgeInsets.zero,
onPressed: () {},
icon: const Icon(
Icons.add,
size: 100,
color: Colors.white,
),
),
],
);
}
}
HERE's THE OUTPUT OF MY CODE
AND THAT's WHAT I WANT TO MAKE
Thanks again!
Stack( alignment: Alignment.topCenter,
children: [ const CircleAvatar( backgroundColor: Colors.black26, radius: 70, ),
IconButton( padding: EdgeInsets.zero, onPressed: () {},
icon: const Icon( Icons.add, size: 100,
color: Colors.white, ), ), ], );
replace this with
CircleAvatar(
backgroundColor: Colors.black26,
radius: 70,
child: GestureDetector(
onTap: () {},
child: const Icon(
Icons.add,
size: 100,
color: Colors.white,
),
),
),

CircleAvatar with IconButton not centered

I want to center the button in the CircleAvatar, but for smaller radius, it doesn't seem to be centering correctly.
CircleAvatar(
backgroundColor: Colors.blue,
radius: 16,
child: IconButton(
icon: Icon(Icons.add),
color: Colors.white,
onPressed: () {
}
}),
),
This is what it looks like:
The IconButton has some default padding, fix the issue by removing the default padding.
Check the code below, it works perfectly.
CircleAvatar(
backgroundColor: Colors.blue,
radius: 16,
child: IconButton(
// remove default padding here
padding: EdgeInsets.zero,
icon: Icon(Icons.add),
color: Colors.white,
onPressed: () {},
),
),
Output of the code:
You can use floatingActionButton to achieve that
Container(
child: floatingActionButton(
child: Icon(Icons.add),
),
),
Hope it helps..!
CircleAvatar generally we used for displaying image, we can have some better option like material button
MaterialButton(
onPressed: () {},
color: Colors.blue,
textColor: Colors.white,
child: Icon(
Icons.add,
size: 16,
),
shape: CircleBorder(),
)
Output:

Reduce padding in app bar buttons in flutter

How can I reduce spacing between button ?
You can see four buttons on app bar takes so much space, I have tried Rows. but not worked
Below is my code --
AppBar(
backgroundColor: Colors.deepOrange,
iconTheme: new IconThemeData(color: Colors.white),
title: Text(
titleString,
style: TextStyle(color: Colors.white),
),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
//iconSize: 20,
onPressed: null,
),
IconButton(
icon: Icon(
Icons.notifications_none,
color: Colors.white,
),
// iconSize: 20,
onPressed: null,
),
//Add more icon here
],
);
You can use VisualDensity and padding arguments together to reduce things:
actions: <Widget>[
IconButton(
visualDensity: VisualDensity(horizontal: -4.0, vertical: -4.0),
padding: EdgeInsets.zero,
icon: Icon(
Icons.search,
color: Colors.white,
),
//iconSize: 20,
onPressed: null,
),
//Add more icon here
],
This worked in my app at least. Hope it's helpful!
The problem is with the IconButton Widget. by default IconButton has a size of 48x48 pixels size and you can read about it in the top answer of this question.
A workaround would be to use the GestureDetector widget to handle your onPressed() method. Below is an example.
actions: <Widget>[
GestureDetector(
onTap: (){
//your code
},
child: Icon(Icons.search)
),
GestureDetector(
onTap: (){},
child: Icon(Icons.notifications)
)
//Add more icon here
],
Try using sizedbox
Example
Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox.fromSize(
size: Size(25, 20), // button width and height
child: InkWell(
splashColor: Colors.white, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.search), // icon
],
),
),
),
),

In flutter Chip Widget, how can I move the deleteIcon to be before the label

I am trying to create a chip where the close button (deleteIcon) is on the left side of the chip label (label).
how can i do that.
here is the unwantted result:
and i want to move the X to the left side of "Hagai"
like this:
Chip(
deleteIcon: Icon( Icons.close, ),
onDeleted: () {setState(() {print("bla");}); }
label: Text("bla",),
),
An update:
after the suggestions answers here is my new code (still dosent work):
Widget build(BuildContext context) {
return Container(
child:
Chip(
label: Text(
"bla",
),
avatar: InkWell(
onTap: () {
print("bla");
},
child: Icon(
Icons.close,
),
),
),
);
}
There is no way to change the direction of Chip Widget. But we can customize the Chip
Chip(
label: Text(
"bla",
),
avatar: InkWell(
onTap: () {},
child: Icon(
Icons.close,
),
),
),
another solution is given by ibhavikmakwana
Additions
as in the above view are visible the same as per requirement but onTap is not working I am working on finding the reason why it's not working.
I have created the custom chip View, for mean while you can use it its working fine
Wrap(
children: <Widget>[
Container(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
decoration: BoxDecoration(
color: Color(0xffDBDBDB),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(20.0),
),
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
runSpacing: 10,
children: <Widget>[
InkWell(
onTap: () {
print("bla");
},
child: Icon(
Icons.close,
),
),
Padding(padding: const EdgeInsets.all(5.0)),
Text(
"bla",
),
],
),
)
],
),
You can either use a RawChip, Chip,
and in avatar field pass your delete icon.
You can wrap your delete icon with InkeWell or GestureDetector to get the onTap event.
RawChip(
label: Text(
"bla",
),
avatar: InkWell(
onTap: () {},
child: Icon(
Icons.close,
),
),
)
Using delete in Avatar doesn't allow tap events, even with Inkwell or GestureDetector.
Use the Directionality widget instead
Directionality(
textDirection: TextDirection.rtl,
child: Chip(
deleteIcon: Icon( Icons.close, ),
onDeleted: () {setState(() {print("bla");}); }
label: Text("bla",),
),
);