ScrollBar class

An interactive scrollbar widget that reflects and adjusts scrolling state.

The scrollbar bounds are determined automatically by querying the associated DiscreteScrollController's viewportExtent (how much content is visible) and totalExtent (the complete virtual size of all items).

Interaction Modes

  • Mouse Clicks and Dragging: Clicking or dragging along the scrollbar track recalculates the proportional offset and invokes DiscreteScrollController.scrollOffset updates, shifting the content view accordingly.

Example Usage

ScrollBar(
  controller: myScrollController,
  direction: LayoutDirection.vertical,
  thumbChar: '█',
  trackChar: '░',
);

Properties and Settings

Property Type Description
controller DiscreteScrollController? Scroll state controller.
direction LayoutDirection Visual orientation (vertical/horizontal).
trackStyle Style Style of the background scrollbar track.
thumbStyle Style Style of the draggable scrollbar thumb.
thumbChar String Character used to draw the slider thumb.
trackChar String Character used to draw the track background.
Inheritance

Constructors

ScrollBar({DiscreteScrollController? controller, int? viewportHeight, int? totalItems, int? scrollOffset, void onScrollChanged(int newOffset)?, LayoutDirection direction = LayoutDirection.vertical, Style trackStyle = const Style(modifiers: Modifier.dim), Style thumbStyle = const Style(modifiers: Modifier.reverse), String thumbChar = '█', String trackChar = '░'})
Creates a ScrollBar widget.

Properties

controller DiscreteScrollController?
The controller that manages the scrolling state.
final
direction LayoutDirection
The visual orientation of the scrollbar.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
The optional key for this widget.
finalinherited
onScrollChanged → void Function(int newOffset)?
Fallback callback invoked when the scroll offset changes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollOffset int?
Fallback property for the current scroll offset.
final
thumbChar String
The character used to render the thumb.
final
thumbStyle Style
The visual style of the thumb indicator.
final
totalItems int?
Fallback property for the total number of items.
final
trackChar String
The character used to render the background track.
final
trackStyle Style
The visual style of the background track.
final
viewportHeight int?
Fallback property for the number of visible items.
final

Methods

createElement() Element
Creates an Element to manage this widget's location in the tree.
inherited
getIntrinsicHeight(int width) int
Computes the intrinsic height of this widget under the given width constraint.
inherited
handleMouseEvent(MouseEvent event, int localX, int localY) → void
Handles track clicks or dragging of the thumb to update the scroll offset.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render(Buffer buffer, Rect area) → void
Renders the widget onto the provided buffer within the specified area.
override
toString() String
A string representation of this object.
inherited

Operators

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