Timeline class

A high-performance Flutter timeline/Gantt chart widget for displaying project schedules.

The Timeline widget provides a scrollable view of project stages, milestones, and activities across a date range. It uses lazy rendering and direct scroll calculations to efficiently handle large datasets (500+ days with 100+ stages).

Features

  • Native Scrolling: Uses Flutter's native ScrollController for all scroll management
  • Direct Calculations: Calculates scroll state directly using pure functions
  • Lazy Rendering: Only renders visible items plus a configurable buffer
  • Data Caching: Caches formatted data to avoid redundant calculations
  • External Configuration: Performance tuning via JSON configuration file

Scroll Architecture

The Timeline uses a simplified scroll architecture that relies entirely on native Flutter ScrollControllers without custom abstraction layers:

  1. Native Controllers: Uses _controllerHorizontal for horizontal and vertical scrolling respectively
  2. Direct State Management: Maintains scroll state in local variables (_centerItemIndex, _visibleStart, _visibleEnd)
  3. Pure Calculation Functions: Calls pure functions from scroll_calculations.dart to calculate center index and visible range

Example

Timeline(
  colors: myColors,
  infos: {'startDate': '2024-01-01', 'endDate': '2024-12-31'},
  elements: myElements,
  elementsDone: [],
  capacities: [],
  stages: myStages,
  openDayDetail: (day) => print('Clicked: ${day['date']}'),
)

See also:

  • TimelineConfiguration for performance tuning options
  • calculateCenterDateIndex for center item calculation
Inheritance

Constructors

Timeline({Key? key, required Map<String, Color> colors, required dynamic infos, required dynamic elements, required dynamic elementsDone, required dynamic capacities, required dynamic stages, String? defaultDate, required dynamic openDayDetail(String, double?, List<String>?, List?, dynamic)?, dynamic openEditStage(String?, String?, String?, String?, String?, double?, String?)?, dynamic openEditElement(String?, String?, String?, String?, String?, double?, String?)?, dynamic updateCurrentDate(String?)?})
const

Properties

capacities → dynamic
final
colors Map<String, Color>
final
defaultDate String?
final
elements → dynamic
final
elementsDone → dynamic
final
hashCode int
The hash code for this object.
no setterinherited
infos → dynamic
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
openDayDetail → dynamic Function(String, double?, List<String>?, List?, dynamic)?
final
openEditElement → dynamic Function(String?, String?, String?, String?, String?, double?, String?)?
final
openEditStage → dynamic Function(String?, String?, String?, String?, String?, double?, String?)?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stages → dynamic
final
updateCurrentDate → dynamic Function(String?)?
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Timeline>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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