'Previous screen time is not updating in flutter
I'm using stateless Widget in my application. By using this single line I can get the output.
DateFormat('HH:mma').format(now).
1.problem is when screen is moving to another screen and back to previous screen at that time time which I have implemented is not updating. 2. time is not updating when I do not touch the screen. and its updating once I touched the screen.
Is there any possibilities to overcome this behavior.
Thanks in advance.
Solution 1:[1]
If you want a widget that for example refreshes every second, you could use a StreamBuilder. For example
Widget build(BuildContext context) {
return StreamBuilder(
stream:
Stream.periodic(const Duration(seconds: 1)),
builder: (context, snapshot) =>
Text(DateFormat('HH:mm:ssa').format(DateTime.now())),
);
}
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 | Ivo Beckers |
