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

1
likes
130
pub points
53%
popularity

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 timed_builder