Is there simple way to get the time in timeago (i.e. "5 mins ago") to update?

I'm using the timeago lib , to convert DateTimes into a string like a moment ago or 5 minutes ago.

class DateTimeUtils { static String timeagoInWords(DateTime dt) { final now = DateTime.now().toLocal(); final diff = now.difference(dt.toLocal()); return timeago.format(now.subtract(diff)); } } 

The problem is that that it doesn't automatically update. Is there any simple way to tell a particular widget to regularly re-calc/re-render?

The only way I can think of, is to create a separate TimeAgo state full widget, that takes a date time, and sets a timer to constantly update itself. Is this the best way to go about it? How would I set that timer? Would having potentially 100s of these statefull widgets on the page cause the app the be laggy (I'm new to Flutter, so I'm not sure if lag is caused by the amount of work the widgets are doing, or just the sheer number of them, because in this example the widgets aren't doing a lot of work, but there would be a lot of them.)

1 Answer

Unless you wrap your widget in a ListView with addAutomaticKeepAlives: false or use a Timer.periodic to rebuild the specific widget periodically following a certain amount of time

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like