TrafficController class
This controller handles:
- Traffic layer visibility toggling
- Traffic intensity score tracking
- Traffic status monitoring
The controller provides real-time traffic information through TrafficModel, allowing users to monitor traffic conditions and control traffic visualization.
Usage example:
final controller = TrafficController(
map: mapInstance,
);
// Toggle traffic visualization
controller.toggleTraffic();
// Access current traffic information
print('Traffic score: ${controller.state.value.score}');
print('Traffic status: ${controller.state.value.status}');
// Listen to traffic condition changes
controller.state.addListener(() {
final model = controller.state.value;
print('Traffic intensity updated:');
print('Score: ${model.score}');
print('Status: ${model.status}');
});
The controller maintains a single subscription to traffic state changes and provides a simple mechanism to toggle traffic visualization on the map.
Traffic score typically ranges from 0 to 10, where:
- 0-3: Light traffic
- 4-7: Moderate traffic
- 8-10: Heavy traffic
Remember to dispose of the controller when it's no longer needed:
controller.dispose();
Constructors
- TrafficController.new({required Map map})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- map → Map
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ ValueNotifier<
TrafficModel> -
no setter
Methods
-
dispose(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toggleTraffic(
) → void -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited