how to add close outside dialog in flutter using getx - flutter

hello I am trying to add like this closing in default dialog in flutter using getx
here is the image
here is my code Get.defaultDialog(
radius: 8,
title: "Test",
titleStyle: const TextStyle(
fontSize: 25, fontWeight: FontWeight.bold),)

Related

How to get the user's display name without getting a null check error in Flutter project?

So, currently, I am creating a Flutter project which is an Android tricycle booking system. I am using a drawer widget inside the application. What I wanted to do is when a user logged in inside the application, their name will be shown in the drawer. However, when I tried following a tutorial video (since I am just a beginner), the screen always becomes red and shows the error:
"Null check operator used on a null value."
I think this is because of me trying to display the name of the user. Does anyone know how to fix this error? I am stuck already for so many days. Any help will be much appreciated!
This is the snippet of my codes for fetching the user's name:
UserAccountsDrawerHeader(
decoration: BoxDecoration(
color: Color(0xFFFED90F),
),
accountName: new Text(userModelCurrentInfo!.first_name! + " " + userModelCurrentInfo!.last_name!, // This is the line that makes it null
style: TextStyle( color: Colors.white,
fontSize: 15,
fontFamily: "Montserrat",
fontWeight: FontWeight.w600,),
),
accountEmail: new Text(user.email!,
style: TextStyle( color: Colors.white,
fontSize: 15,
fontFamily: "Montserrat",
fontWeight: FontWeight.w600,),
),
currentAccountPicture: new CircleAvatar(
radius: 50.0,
backgroundImage: AssetImage("assets/images/machu.jpg"),
),
),
This is the code for reading the current user details:
static void readCurrentOnlineUserInfo() async
{
final FirebaseAuth fAuth = FirebaseAuth.instance;
User? currentFirebaseUser;
currentFirebaseUser = fAuth.currentUser;
DatabaseReference userRef = FirebaseDatabase.instance
.ref()
.child("passengers")
.child(currentFirebaseUser!.uid);
userRef.once().then((snap)
{
if(snap.snapshot.value != null)
{
userModelCurrentInfo = UserModel.fromSnapshot(snap.snapshot);
print("name" + userModelCurrentInfo!.first_name.toString());
print("id" + userModelCurrentInfo!.id.toString());
}
});
}
Another thing that I notice:
Upon logging in, it will show the null error, then when I go to another tab and come back to the page that says null error, it suddenly disappears. Why tho?
Try this.
Added not null conditions
UserAccountsDrawerHeader(
decoration: BoxDecoration(
color: Color(0xFFFED90F),
),
accountName: userModelCurrentInfo!.first_name !=null && userModelCurrentInfo!.last_name !=null ?
new Text(userModelCurrentInfo!.first_name! + " " + userModelCurrentInfo!.last_name!,
style: TextStyle( color: Colors.white,
fontSize: 15,
fontFamily: "Montserrat",
fontWeight: FontWeight.w600,),
):new Text('')// added null condition here,
accountEmail: new Text(user.email!,
style: TextStyle( color: Colors.white,
fontSize: 15,
fontFamily: "Montserrat",
fontWeight: FontWeight.w600,),
),
currentAccountPicture: new CircleAvatar(
radius: 50.0,
backgroundImage: AssetImage("assets/images/machu.jpg"),
),
),

Reset State of Slide_to_act widget in flutter

I had a problem when I slide my slide_to_act widget it works correctly and it push me to another page. but when I use nav.pop ( when I turn back to old page ) my slide_to_act button looks done. I want to reset it.
SlideAction(
height: 70,
sliderRotate: false,
alignment: Alignment.centerRight,
onSubmit: () {
slideAnimated_push(
context,
ConfirmPage(
total: summedPrice.toInt(), slevee: slevee));
},
innerColor: Colors.white,
outerColor: StGreen,
elevation: 1,
text: 'Slide to Confirm',
textStyle: const TextStyle(
fontFamily: 'RaleWay',
fontSize: 20,
color: Colors.white,
),
),[enter image description here][1]
May be you can reset it after going to the other page.

How to change Text color with Get in Flutter

How can i change my Texts color immedietly
TextStyle get headingStyle {
return GoogleFonts.lato(
textStyle: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
color:Get.isDarkMode?Colors.white:Colors.black);
}
color changes when i hot reloud but doesn't change when i clicked the button(button changes isDarkMode )
Try put the Obx.
It's create an observable in your code
TextStyle get headingStyle {
return Obx(() => GoogleFonts.lato(
textStyle: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
color:Get.isDarkMode?Colors.white:Colors.black));
}

How to diplay a hexadecimal emoji in flutter

I would like to display the emoji 🤑 while only having the hexadecimal value of it.
var line = "testing is forever 🤑";
Text(
"${line}",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xFF008080)),
),
Try below code hope its helpful to you. Refer Unicode Charecter here
Text(
'\u{1F602}',
style: TextStyle(
fontSize: 25,
),
),
Your Result screen->
Or in VS Code Pressed Window + . and open the emoji picker box choose your wanted emoji and select it
Text(
'🤑',
style: TextStyle(
fontSize: 30,
),
),
Your result screen->
I was able to fix this by using the HtmlCharacterEntities and the HtmlUnescape
HtmlUnescape().convert(HtmlCharacterEntities.decode("testing is forever 🤑"))

Dart - How to a change the color of my raisedButton after clicking in dart?

so i've been struggling to change the color of my button from green to red for my flutter app. Most of the online resources are confusing me. This is my following code.
new RaisedButton(key:null, onPressed:buttonPressed,
color: Colors.green,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),void buttonPressed(){
}
I want to click it and it turn green, or even better. Click it, so it turns gray. Then click another button that states "confirm", and it would make all the grey buttons that have been clicked red. Regardless, I'm just trying to understand how to make the button change color after being clicked.
Basically, what you need to do is,
Make RaisedButton color a class-level variable instead of constant as you have now.
Initialize that variable to some color value in initState method.
In the onPressed handler of RaisedButton, do the following:
Change that variable to some color value of your liking.
Trigger Repaint (so that the new color gets painted) i.e. call setState method.
Last but not least, you'll need to have all the code above part of a stateful widget.
Hopefully, it's clear enough, let us know if you'd need some code sample as well.
bool turnToRed = false;
bool colorIsGreen = true;
RaisedButton(key:null, onPressed: (){
setState((){
colorIsGreen = !colorIsGreen;
});
},
color: colorIsGreen ? Colors.green :turnToRed ? Colors.red : Colors.grey,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),
RaisedButton(key:null, onPressed: (){
setState((){
turnToRed = !turnToRed;
});
},
color: Colors.red
child:
new Text(
"Confirm",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),