Interval class Null safety

An interval between two points, start and end.

Interval can calculate unions, intersections, and differences between individual intervals:

final a = Interval(0, 3);
final b = Interval(2, 5);
print(a.union(b)); // [[0, 5]]
print(a.intersection(b)); // [2,3]
print(a.difference(b)); // [[0, 2]]

See IntervalTree for calculating more complex unions, intersections, and differences between collections of intervals.

Notice that the Interval class name unfortunately clashes with the Interval class from the Flutter animation library. However, there are two ways around this problem. Either use the syntax with list literals, or import either library with a name prefix, for example:

import 'package:interval_tree/interval_tree.dart' as ivt;

final interval = ivt.Interval(1, 2);
Inheritance
Annotations
  • @immutable

Constructors

Interval(dynamic start, dynamic end)
Creates an interval between start and end points.
Interval.copy(Interval other)
Creates a copy of the other interval.

Properties

end → dynamic
Returns the end point of this interval.
read-only
hashCode int
Returns the hash code for this interval.
read-onlyoverride
length → dynamic
Returns the length of this interval.
read-only
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
start → dynamic
Returns the start point of this interval.
read-only

Methods

compareTo(Interval other) int
Compares this interval to the other interval.
override
contains(Interval other) bool
Returns true if this interval contains the other interval.
difference(Interval other) Iterable<Interval>?
Returns the difference between this interval and the other interval, or null if the other interval contains this interval.
intersection(Interval other) Interval?
Returns the intersection between this interval and the other interval, or null if the intervals do not intersect.
intersects(Interval other) bool
Returns true if this interval intersects with the other interval.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() String
Returns a string representation of this interval.
override
union(Interval other) Interval
Returns the union of this interval and the other interval.

Operators

operator <(Interval other) bool
Returns true if this interval start or ends before the other interval.
operator <=(Interval other) bool
Returns true if this interval starts or ends before or same as the other interval.
operator ==(Object other) bool
Returns true if this interval starts and ends same as the other interval.
override
operator >(Interval other) bool
Returns true if this interval starts or ends after the other interval.
operator >=(Interval other) bool
Returns true if this interval starts or ends after or same as the other interval.