timer_builder 2.0.0 copy "timer_builder: ^2.0.0" to clipboard
timer_builder: ^2.0.0 copied to clipboard

A widget that rebuilds itself on scheduled, periodic, or dynamically generated time events.

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.

animated image

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()}");
      }
    );
  }
  
}

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");
      }
    );
  }
  
}

162
likes
150
points
13.5k
downloads

Publisher

unverified uploader

Weekly Downloads

A widget that rebuilds itself on scheduled, periodic, or dynamically generated time events.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on timer_builder