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),
),
),
),
Any suggestions to change the color of the ElevateButton below?
child: ElevatedButton(
child: Text(
'Subscribe',
style: TextStyle(
color: gray900,
fontFamily: 'Lexend Exa',
fontSize: 20),
),
onPressed: fetchOffersMonthly,
),
Try below code hope its helpful to you. refer documentation Here for ElevatedButton
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,//choose your color on your need
),
child: Text(
'Subscribe',
style: TextStyle(
color: gray900,
fontFamily: 'Lexend Exa',
fontSize: 20),
),
onPressed: fetchOffersMonthly,
),
Your result screen ->
Use ButtonStyle to change the color
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green)),
onPressed: () { },
child: Text(""),
),
ElevatedButton(
child: Text('Subscribe'),
onPressed: () {},
style: ElevatedButton.styleFrom(
primary: Colors.purple,
textStyle: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold),
),
)
I have created a mobile application and I was using a font family called Baloo Paaji 2 from google and I have faced an issue of extra spacing created between my 2 text widgets. Below you can see the image of the view.
The text I am talking about is the Welcome! Lakshya Jain. The space between the 2 is way too much. There is no SizedBox or Padding added to the text widget. I tried using 2 different methods to see if the method was the problem. The 2 different methods are shown below.
Method 1
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
],
),
Method 2
Text.rich(
TextSpan(
text: "Welcome !\n",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
children: [
TextSpan(
text: userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
],
),
),
Now I used another method which fixed this issue but created another one.
The Method 3 Screenshot is as follows.
Now the spacing issue is fixed but it created as the text has moved down a little. I want it to be center without the huge gap.
The code for this method is as followed.
Stack(
alignment: Alignment.topLeft,
clipBehavior: Clip.none,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Positioned(
top: 20.0,
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
The full code for the whole header is as followed
class HomeHeader extends StatelessWidget {
#override
Widget build(BuildContext context) {
// Get User UID
final user = Provider.of<MyAppUser>(context);
return Stack(
clipBehavior: Clip.none,
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 15.0),
width: MediaQuery.of(context).size.width,
height: 230.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(255, 18, 54, 1.0),
Color.fromRGBO(255, 164, 29, 1.0),
],
),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(59.0),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
StreamBuilder(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
UserDataCustomer userData = snapshot.data;
return Row(
children: [
ClipOval(
child: CachedNetworkImage(
height: 70,
width: 70,
imageUrl: userData.profilePicture,
),
),
SizedBox(
width: 10.0,
),
Stack(
alignment: Alignment.topLeft,
clipBehavior: Clip.none,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Positioned(
top: 20.0,
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
// Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// "Welcome !",
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 18.0,
// fontWeight: FontWeight.w600,
// ),
// ),
// Text(
// userData.fullName,
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 24.0,
// fontWeight: FontWeight.w900,
// ),
// ),
// ],
// ),
// Text.rich(
// TextSpan(
// text: "Welcome !\n",
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 18.0,
// fontWeight: FontWeight.w600,
// ),
// children: [
// TextSpan(
// text: userData.fullName,
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 24.0,
// fontWeight: FontWeight.w900,
// ),
// ),
// ],
// ),
// ),
],
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection("Users Database")
.doc(user.uid)
.collection("Cart")
.snapshots(),
builder: (context, snapshot) {
int totalItems = 0;
if (snapshot.connectionState == ConnectionState.active) {
List documents = snapshot.data.docs;
totalItems = documents.length;
}
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CartScreen(),
),
);
},
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(
10.0,
),
),
child: Center(
child: Text(
"$totalItems" ?? "0",
style: TextStyle(
fontSize: 20.0,
fontFamily: "BalooPaaji",
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
);
},
),
],
),
),
Positioned(
top: 200.0,
child: SearchBar(
width: MediaQuery.of(context).size.width * 0.83,
hintText: "Location",
),
),
],
);
}
}
Someone please help me and fix this issue as soon as possible.
I guess you are trying to reduce gap / padding between the 2 lines. If that is so, then the easiest way is to wrap them inside container and give it a fixed height. Check below.
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 20, // assign height as per your choice
child: Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
),
Container(
height: 26, // assign height as per your choice
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
NOTE: you can also give height inside the Text widget
Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
height: 1.2, // assign height to fontSize ratio as per your choice
),
),
Try to change :
This : fontWeight: FontWeight.w600,
To : fontWeight: FontWeight.w500,
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,
),
),
)
InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: SizedBox(
height: 25,
width: screenWidth *65,
child: Container(
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),
),
Is this what you are looking for?
Container(
padding: EdgeInsets.all(6),
width: double.infinity,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5))
),
color: Colors.blueAccent,
onPressed: () => print('pressed'),
child: Text('Confirm',
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500
),
)
),
),
Remove SizedBox widget as it not of any issue in your current widget tree anyway as you are using container already
and use those height and width parameter inside container widget
try this
InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: Container(
height: 25,
width: screenWidth *65,
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),