Whether you're building a personalized greeting feature or enhancing the user experience, this code helps you dynamically wish users 'good morning,' 'good afternoon,' or 'good evening' based on the current time. Copy, paste, and customize it for your Flutter projects!
Step 1: Create a Custom Function:
greetUser
Step 2: Copy And Paste the below code to Code Editor:
String greetUser() {
final currentTime = DateTime.now();
final hour = currentTime.hour;
if (hour < 12) {
return 'morning';
} else if (hour < 18) {
return 'afternoon';
} else {
return 'evening';
}
}
Step 3: Use the Function in the Rich text
That's All!
If you have any specific questions or if there's anything else you'd like to know, feel free to ask! ๐
If you need any help in Integration you can Get help via Book 1:1 Session