Flutter MouseRegion is not working when the child is a Chip Widget - flutter

The mouse cursor in my flutter web program is not changing to a click cursor on hover when the child is a Chip widget. I changed the Chip to a Text and a Container widget and the mouse cursor changes without any issues.
Below is the code of the MouseRegion.
return MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
width: 200,
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () {},
child: Chip(
backgroundColor: kLightPrimary,
avatar: const Icon(
Feather.phone_call,
size: 18.0,
color: kPrimaryColor,
),
label: Text(
"Test num",
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500, color: kPrimaryColor),
textAlign: TextAlign.end,
),
padding: const EdgeInsets.all(kDefaultPadding),
),
),
),
),

Instead of MouseRegion and GestureDetector on a Chip, you want to use ActionChip instead.
ActionChip(
onPressed() {/* use onPressed even if it would be empty */}
backgroundColor: kLightPrimary,
avatar: const Icon(
Feather.phone_call,
size: 18.0,
color: kPrimaryColor,
),
label: Text(
"Test num",
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500, color: kPrimaryColor),
textAlign: TextAlign.end,
),
padding: const EdgeInsets.all(kDefaultPadding),
)

Change your GestureDetector to InkWell this is working for me.
return Container(
width: 200,
alignment: Alignment.centerRight,
child: InkWell( //use InkWell insted of GestureDetector
onTap: () {},
child: Chip(
backgroundColor: kLightPrimary,
avatar: const Icon(
Feather.phone_call,
size: 18.0,
color: kPrimaryColor,
),
label: Text(
"Test num",
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500, color: kPrimaryColor),
textAlign: TextAlign.end,
),
padding: const EdgeInsets.all(kDefaultPadding),
),
),
),

Related

How can I give my text a background color?

I want to give color to the text background like the picture below:
while mine is still like this:
And the code that I have written is like this:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),
body: Center(
child: TextButton.icon(
style: TextButton.styleFrom(
textStyle: TextStyle(color: Colors.blue),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: Text('Last Activity'),
label: Icon(Icons.chevron_right),
),
),
Set the style parameter in your Text widget:
Text(
'Hello, World!',
style: TextStyle(fontSize: 32, backgroundColor: Colors.green),
);
See also
TextStyle (flutter.dev)
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
backgroundColor: Colors.indigo[400],
),
),
Refer below code hope its help to you, I have try 2 ways TextButton.icon and Row
1. Using TextButton Widget
TextButton.icon(
style: TextButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: const Color.fromRGBO(60, 75, 175, 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Text('Last Activity'),
label: const Icon(Icons.chevron_right),
),
Result Using TextButton.icon->
2. Using Row
GestureDetector(
onTap: () {},
child: Container(
height: 30,//change on your need
width: 120,//change on your need
padding: const EdgeInsets.all(5),
alignment: Alignment.center,
color: const Color.fromRGBO(60, 75, 175, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
Text(
'Last Activity',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.chevron_right,
color: Colors.white,
),
],
),
),
),
Result Using Row->
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),

Reducing the space between icon and text - Flutter OutlinedButton

Is there an easy way to reduce the space between the icon and text on an OutlinedButton?
Below is my code. Have made a few different attempts but no luck.
OutlinedButton.icon(
onPressed: () {},
icon: Icon(Icons.flash_on_outlined, size: 20.0),
label: Text(
'Surge',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
style: OutlinedButton.styleFrom(
padding: EdgeInsets.zero,
//fixedSize: Size(40, 25),
backgroundColor: Colors.blue[100],
side: BorderSide(
color: Colors.blue,
width: 1,
),
),
),
OutlinedButton.icon(
onPressed: () {},
icon: Wrap(
// mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(Icons.flash_on_outlined, size: 20.0),
Text(
'Surge',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
)
],
),
label: Text(""),
style: OutlinedButton.styleFrom(
padding: EdgeInsets.zero,
//fixedSize: Size(40, 25),
backgroundColor: Colors.blue[100],
side: BorderSide(
color: Colors.blue,
width: 1,
),
),
)
You are using OutlinedButton.icon. If you look into its source code, you'll see that it's nothing magical at all: it simply puts your icon and text in a Row and places a SizedBox in the middle as a gap, its source code is as follows:
// Flutter source code: `outlined_button.dart`, line 378.
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)],
);
So, if you don't like this default 8-unit gap, simply don't use .icon constructor. Just use the normal constructor and pass in a Row as its child, with whatever gap you want:
OutlinedButton(
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.star),
SizedBox(width: 8),
Text('Add to bookmark'),
],
),
onPressed: () {},
)
The best way to implement such case I think is to replace icon button with button with RichText as a child:
OutlinedButton(
onPressed: () {},
child: RichText(
text: TextSpan(children: [
// Icon as a font character
TextSpan(
text: String.fromCharCode(Icons.flash_on_outlined.codePoint),
style: TextStyle(
color: Colors.amber,
fontFamily: Icons.flash_on_outlined.fontFamily,
package: Icons.flash_on_outlined.fontPackage,
),
),
// Button text
TextSpan(
text: 'Surge',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
]),
),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.blue[100],
side: BorderSide(
color: Colors.blue,
width: 1,
),
),
)
This solution removes any margin from an icon.
your size, about the icon and the text, are block or you can modify it?

How to add icon from the assets/icons into my button components

this is my button component code :
Widget build(BuildContext context) {
return MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
side: BorderSide(color: kPrimaryColor)
),
padding: padding,
color: color,
minWidth: 280,
onPressed: press,
child: Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
);
}
Wrap your child with a Row and add the icon as the second element of your Row's children. It will turn out something like below:
child: Row(
children: [
Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
Image.asset('assets/icons/my_icon.png'),
],
),
You can use a TextButton.icon widget
And flip the label and icon (both accept a widget)
TextButton.icon(
icon: Text("MyText",
style: TextStyle(
fontSize: 11.0,
fontFamily: "Raleway"
),
),
label: Image.asset('assets/myImage.png', width: 20.0,height: 20.0,),
style: ButtonStyle(
// backgroundColor:
// MaterialStateProperty.all(Colors.green.shade200),
overlayColor: MaterialStateProperty.all(Colors.green),
side: MaterialStateProperty.resolveWith((states) {
return BorderSide(color: Colors.grey, width: 1);
})),
)
Inside the TextButton, I manage to add a row that contains icon and text
TextButton(
onPressed: (){},
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.arrow_back_ios,
color: Themes.primaryColor,
),
Text(
'Back',
style: TextStyle(
fontSize: 17,
color: Themes.primaryColor,
),
),
],
),
),

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)),
],
)),
),
),

Text widget with circular background in flutter

How can I get this type of rounded background in Text widget?
You can achieve it by
CircleAvatar(
backgroundColor: Colors.grey,
child: Center(
child: Text(
"B",
style: TextStyle(color: Colors.black),
),
),
)
Screenshot:
You can also use ClipOval
ClipOval(
child: Container(
color: Colors.grey,
padding: EdgeInsets.symmetric(horizontal: 30),
child: Text(
"B",
style: TextStyle(color: Colors.black, fontSize: 90),
),
),
)
Just use a FAB:
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.grey,
child: Text(
"A",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.italic,
),
),
)