A Flutter package that provides a widget to listen to the system's datetime and trigger a rebuild based on the specified time unit
Support the project by giving the repo a ⭐ and showing some ❤️!
Import the package in your Dart code:
import 'package:datetime_loop/datetime_loop.dart';
Use the DateTimeLoopBuilder
widget in your Flutter app to rebuild UI elements based on system time updates:
DateTimeLoopBuilder(
timeUnit: TimeUnit.seconds,
builder: (context, dateTime, child) {
return Column(
children: [
Container(
width: 200,
height: 200,
color: Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0),
),
Text('$dateTime'),
],
);
}
)
New in version 1.3.0
! Use the DateTimeLoopController
to listen to datetime updates programmatically via a stream:
final controller = DateTimeLoopController(timeUnit: TimeUnit.minutes);
controller.dateTimeStream.listen((dateTime) {
print('Current time: $dateTime');
});
// Don’t forget to dispose of the controller when done
controller.dispose();
You can check more examples of using this widget here
Please file any issues or feedback here.