FpsCounter class

A simple 1-second rolling FPS counter for camera-preview apps.

Call tick once per processed frame; tick returns true at most once per second (when fps has been refreshed), so the caller can use its return value to decide whether to trigger a widget rebuild.

Usage:

final _fpsCounter = FpsCounter();
int _fps = 0;

void onFrame() {
  if (_fpsCounter.tick() && mounted) {
    setState(() => _fps = _fpsCounter.fps);
  }
}

Constructors

FpsCounter()

Properties

fps int
The most recently computed FPS value. Starts at 0 until the first 1-second interval completes.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Reset all counters. Useful when switching cameras.
tick() bool
Record a frame. Returns true when fps was refreshed (i.e. at most once per second); callers typically guard setState(...) on the result.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited