'Change a text and an icon according to the current date of a time zone
How do i change an icon and a text according to the current date?
For example lets say icon A and a text that says this is the first part of the year appears from January first to June 30th. How do I write my code in flutter so the text changes to this is the second part of the year and then the icon changes to icon B when the current date is July to December. Also, I don't want the code to take the current date from the location of the phone. I want to use the current date of the time zone utc+1.
Also, I got a flutter package for a clock. Here is the link clock package.
The documentation of the package is not really that detailed. How do I code the clock so it doesn't show the current time of the phone but the current time of a particular time zone I choose. eg utc+1. Thanks a lot for your time.
Solution 1:[1]
You can check the month of the current time adjusted per your requirements and display the correct text/icon. Here is an example of how to handle the text. You would follow the same approach for the icon and any other adjustments you'd want to make.
@override
Widget build(BuildContext context) {
final now = DateTime.now().toUtc().add(const Duration(hours: 1));
return Text(
now.month < 7
? 'This is the first half of the year'
: 'This is the second half of the year',
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan Harms |
