flutter how to get rid of a icon padding? - flutter

I did eveything solution on Stackoverflow
but it still has a space horizontally
I want to set these icons very closely each other
my code is this
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MediaQuery.removePadding(
context: context,
removeLeft: true,
removeRight: true,
child: GestureDetector(
onTap: () {},
child: Container(
padding: const EdgeInsets.all(0.0),
width: 30.0,
child: IconButton(
icon: Icon(
Icons.keyboard_arrow_right,
color: Color(0xff60B906),
),
color: Color(0xff60B906),
iconSize: 30,
),
),
),
),
MediaQuery.removePadding(
context: context,
removeLeft: true,
removeRight: true,
child: GestureDetector(
onTap: () {},
child: Container(
padding: const EdgeInsets.all(0.0),
width: 30.0,
child: IconButton(
icon: Icon(
Icons.keyboard_arrow_right,
color: Color(0xff60B906),
),
color: Color(0xff60B906),
iconSize: 30,
),
),
),
),
],
),
any solution that difference to mine please?
current image
and I want it to be very close

You can use Stack Widget
SAMPLE CODE
Stack(
alignment: Alignment.center,
children: <Widget>[
IconButton(
onPressed: null,
icon: Icon(
Icons.keyboard_arrow_right,
color: Color(0xff60B906),
),
color: Color(0xff60B906),
iconSize: 30,
),
Positioned(
right: 20,
child: IconButton(
onPressed: null,
icon: Icon(
Icons.keyboard_arrow_right,
color: Color(0xff60B906),
),
color: Color(0xff60B906),
iconSize: 30,
),
),
],
)
OUTPUT

if you want to achieve this
there are two options
1- download it as PNG image to your folder assets and make it a child
instead of row
GestureDetector(
onTap: () {},
child: Image.asset(
"imagePath",
color: Color(0xff60B906),
height: 16,
width: 16,
),
),
2- if you want it as Icon make it as Icon data from SVG from this site
https://fluttericon.com/
and make it as usual

Stack them on top of each other using a Stack, then wrap one of them in a padding with only left padding of the points you need to get it look the way you want.

Related

How to add image for buttons in flutter

I am trying to add image for buttons in flutter like below the image. Here i have used ElevatedButton. So How to set background image for the ElevatedButton. I do not know how to add image for it. If anyone know please help to find the solution.
child:SingleChildScrollView(
child: Wrap(
alignment: WrapAlignment.center,
runSpacing: 20.0, // Or more
spacing: 20, // Or more
children: [
const SizedBox(
height: 520,
),
SizedBox(
width: double.infinity, // <-- Your width
height: 50, // <-- Your height
),
SizedBox(
height: 50, // <-- Your height
child: ElevatedButton(
onPressed: () {
onSignIn(context);
},
style: ElevatedButton.styleFrom(
primary: Color(0xff557de3),
shape: StadiumBorder()
),
child: const Text(
"GMAIL",
style: TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold
),
),
),
),
SizedBox(
height: 50, // <-- Your height
child: ElevatedButton(
onPressed: () {
//validateForm();
},
style: ElevatedButton.styleFrom(
primary: Color(0xff557de3),
shape: StadiumBorder()
),
child: const Text(
"Phone",
style: TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold
),
),
),// Button
),
],
),
),
You can use:
ElevatedButton.icon(
onPressed: (){},
icon: Icon(Icons.phone),
label: Text("hello"),
),
You can use gestures detector
GestureDetector(
onTap: () {
debugPrint('The image button has been tapped');
},
child: SizedBox(
width: 300,
height: 100,
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover,
),
),
),
or use icon button
IconButton(
splashRadius: 100,
iconSize: 200,
icon: Ink.image(
image: const NetworkImage(
'https://picsum.photos/250?image=9'),
),
onPressed: () {
// do something when the button is pressed
debugPrint('Hi there');
},
),
You can add image from asset:
ElevatedButton(
onPressed: () {},
child: Image.asset('your_asset_path')
)
Or you can add network image:
ElevatedButton(
onPressed: () {},
child: Image.network('your_image_url_path')
)
Or you can create your custom button:
GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('your_asset_image_path'),
),
),
)
)
Instead of using the ElevatedButton, have you tried IconButton, GestureDetector, InkWell, InkResponse and Material?
IconButton(
splashRadius: 100, // optional
onPressed: {YOUR_LOGIC_COMPONENT}
icon: Container(
child : {YOUR_WIDGET},
),
),
or
GestureDetector(
child: SizedBox(child: {YOUR_WIDGET}),
onTap: {YOUR_LOGIC_COMPONENT},
);
or
InkWell(
child: CircleAvatar(child: {YOUR_WIDGET}),
onTap: {YOUR_LOGIC_COMPONENT},
);
You can use MaterialButton and customize it according to your need.
MaterialButton(
padding: EdgeInsets.all(8.0),
textColor: Colors.white,
splashColor: Colors.red,
elevation: 8.0,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(''), //some asset image
fit: BoxFit.cover),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(),
),
),
// ),
onPressed: () {
print('Tapped');
},
),

Container widget overflows other widgets- Flutter

This is the expected screen and the container will collapse and expand based on the text displayed and should only occupy the space left out by placing other icons.
But see the flutter implemented screen.
The icons are moved to the right on container expansion and shows overflowed pixel error.
My code
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(
Icons.menu,
color: Colors.black,
size: 34,
),
onPressed: () {},
),
//container section
GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius: BorderRadius.circular(40.0)),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Row(children: const <Widget>[
Text(
"Content is here",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black54,
fontSize: 19.0,
fontWeight: FontWeight.bold),
),
Icon(
Icons.arrow_drop_down,
color: Colors.black,
),
]),
),
),
),
onTap: () {
//todo show bottom sheet dialog here.
},
),
const Spacer(), // I just added one line
IconButton(
icon: Image.asset('assets/images/ic_scan.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_notification.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_search.png'),
iconSize: 20,
onPressed: () {},
),
],
),
);
Remove the spacer and add the dropdown in a flexible widget
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(
Icons.menu,
color: Colors.black,
size: 34,
),
onPressed: () {},
),
Flexible(//<-------Flexible
child: GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius: BorderRadius.circular(40.0)),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Row(
children: const <Widget>[
Flexible(//<-------Flexible
child: Text(
"Content is here",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black54,
fontSize: 19.0,
fontWeight: FontWeight.bold),
),
),
Icon(
Icons.arrow_drop_down,
color: Colors.black,
),
]),
),
),
),
onTap: () {
//todo show bottom sheet dialog here.
},
),
),
//Spacer() //<--------remove this
IconButton(
icon: Image.asset('assets/images/ic_scan.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_notification.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_search.png'),
iconSize: 20,
onPressed: () {},
),
],
),
);

Positioning in list tile drawer flutter?

I have this drawer in a flutter app. The List Tile has a leading, title and a trailing. I used an icon button in the leading in the first tile as opposed to using asset image in other tiles, so the alignment got a little distorted. How can I make it align with rest of the tiles. This is the code of the first tile:
SizedBox(
height: 40,
child: ListTile(
leading: IconButton(
onPressed: () {},
icon: const Icon(Icons.notifications_none_sharp,
color: Colors.white),
),
title: Transform.translate(
offset: const Offset(-14, 0),
child: const Text('Notifications',
style: TextStyle(
fontSize: 12, color: Colors.white))),
trailing: SizedBox(
),
other list tiles code :
SizedBox(
height: 40,
child: ListTile(
leading: SizedBox(
height: 20,
width: 20,
child: Image.asset(
'assets/sideMenu/Group.png',
),
),
title: Transform.translate(
offset: const Offset(-14, 0),
child: const Text(
'Grid',
style: TextStyle(
fontSize: 12,
color: Colors.white,
),
),
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const BlurGrid()));
},
),
),
I just want the notification icon to align with other leading asset images:
just replace the IconButton with an Icon wrapped in a GestureDetector and then add padding if required
SizedBox(
height: 40,
child: ListTile(
leading: GestureDetector(
onTap: () {} ,
child: const Icon(
Icons.notifications_none_sharp,
color: Colors.white,
),
),
title: Transform.translate(
offset: const Offset(-14, 0),
child: const Text('Notifications',
style: TextStyle(fontSize: 12, color: Colors.white))),
trailing: SizedBox(),
),
),
that caused by IconButton.
if you want to keep use the IconButton, then you have to remove the padding and reset the constrain.
ListTile(
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.abc),
padding: EdgeInsets.zero, // remove the padding
constraints: BoxConstraints(), // reset the constarins
),
title: Text("abcdef"),),

How do I add Social Media Links/Buttons To My App in Flutter?

I would like to change the buttons below the email card in the picture to social media links. However, I'm having trouble finding icons for those. I would like to be able to manipulate the icon and change the color.
Here's My App
One solution I came up with was to use an image asset inside instead of an icon, but by doing this I am unable to change the color.
Here's My Code:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.white,
child: IconButton(
onPressed: null,
icon: Icon(
Icons.ac_unit,
color: Colors.black,
),
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.white,
child: IconButton(
onPressed: null,
icon: Icon(
Icons.ac_unit,
color: Colors.black,
),
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.white,
child: IconButton(
onPressed: null,
icon: Icon(
Icons.ac_unit,
color: Colors.black,
),
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.white,
child: IconButton(
onPressed: null,
icon: Icon(
Icons.ac_unit,
color: Colors.black,
),
),
),
),
],
),
You can use this package: https://pub.dev/packages/font_awesome_flutter
With this one, you can styles for the icon easily:
Icon(FontAwesomeIcons.facebook, color: widget.color, size: 16.0)
The name of icon can be found here: https://fontawesome.com/v5.15/icons?d=gallery&p=2
use package font_awesome_flutter
https://pub.dev/packages/font_awesome_flutter
Icon(
FontAwesomeIcons.instagram,
size: 100,
),
Icon(
FontAwesomeIcons.facebook,
size: 100,
),
Icon(
FontAwesomeIcons.whatsapp,
size: 100,
),

Button with icon and text position left

I use flutter to do RaisedButton with icon and the the icon and text I want change position to left. How to do it? This is my code for button.
I want do it like in the image:
Card(
child: SizedBox(
width: double.infinity,
height: 60,
child: RaisedButton.icon(
icon: Icon(Icons.home,
size: 40, color: Theme.of(context).primaryColor),
color: Colors.white,
textColor: Theme.of(context).primaryColor,
label: const Text('Electrical and Wiring',
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 15)),
onPressed: () => {},
),
),
),
What you can do you can use Directionality widget in flutter with TextButton.icon(). Here is the Code.
Directionality(
textDirection: TextDirection.rtl,
child: TextButton.icon(
onPressed: null,
icon: Icon(
CupertinoIcons.ellipsis_circle_fill,
color: Colors.green,
),
label: Text(
"Business Name",
style: Theme.of(context).textTheme.subtitle1,
),
),
),
And here is the View.
in the Raised Button Widget you can put a Row() or a Column() as the child, so it can be easily done like this,
RaisedButton(
child: Row(
children: <Widget>[
Icon(Icons.call),
Text('Your Text'),
],
),
onPressed: (){
//Actions
}),
You can achieve that using RaisedButton.icon() widget..
You can get more information from documentation.
Here's a minimal example for you..
RaisedButton.icon(onPressed: null, icon: null, label: null);
Try this
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {},
child: Card(
child: SizedBox(
width: double.infinity,
height: 60,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Icon(Icons.home,
size: 40, color: Theme.of(context).primaryColor),
),
Text('Electrical and Wiring',
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 15)),
],
)),
),
),