0 purchases
timer builder
TimerBuilder #
A widget that rebuilds itself on scheduled, periodic, or
dynamically generated time events.
Here are some use cases for this widget:
When showing time since or until a specified event;
When the model updates frequently but you want to limit UI update frequency;
When showing current date or time;
When the representation a widget depends on a certain time event.
Examples #
Periodic rebuild #
import 'package:timer_builder/timer_builder.dart';
class ClockWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TimerBuilder.periodic(Duration(seconds: 1),
builder: (context) {
return Text("${DateTime.now()}");
}
);
}
}
copied to clipboard
Rebuild on a schedule #
import 'package:timer_builder/timer_builder.dart';
class StatusIndicator extends StatelessWidget {
final DateTime startTime;
final DateTime endTime;
StatusIndicator(this.startTime, this.endTime);
@override
Widget build(BuildContext context) {
return TimerBuilder.scheduled([startTime, endTime],
builder: (context) {
final now = DateTime.now();
final started = now.compareTo(startTime) >= 0;
final ended = now.compareTo(endTime) >= 0;
return Text(started ? ended ? "Ended": "Started": "Not Started");
}
);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.