AdvStory
AdvStory Docs
Search
K
Comment on page

AdvStoryController

This page contains infromation of AdvStoryController properties.
Provides methods for manipulating AdvStory default flow and for listening events.
// Define controller in your code
final controller = AdvStoryController();
...
AdvStory(
controller: controller,
...
)

Controller Variables

hasClient

Returns true if a story view is currently visible. Some methods like toNextStory, toPreviousCluster can't be used and throws an exception if the story view is not visible.

position

Displaying story and content position. Returns 0,0 if no story is currently displayed.

storyCount

Total count of stories.

contentCount

Total content count in currently displaying story

isGesturesDisabled

Returns true if gestures are disabled, false otherwise.

isComponentsVisible

Returns true if footer, header and indicators are visible, false otherwise.

isPaused

Returns true if the story is paused, false otherwise.

Controller Methods

addListener(StoryEventCallback callback)

Register a closure to be called when any story event happens. Events can be triggered by the user or automatically. Event types are:
  • trayTap
  • nextContent
  • previousContent
  • nextStory
  • previousStory
  • pause
  • resume
  • close
Listener Definition
typedef StoryEventCallback = FutureOr<void> Function(
/// Event type
StoryEvent event,
/// Current cluster and story index in cluster
StoryPosition position,
);

removeListener()

Removes a previously registered closure from the list of closures that are notified when an event happened. If the given listener is not registered, the call is ignored. Call this method when you don't need to listen events anymore.

disableGestures()

Prevents gesture events. Prevents user from skipping between stories or clusters. Also user can't pause or close cluster by gestures. Note that Android back button still works for closing and automatic skipping still works on story duration end. If you want to prevent this, use combination of disableGestures and pause.
Gestures should enable by calling enableGestures after calling this method. Otherwise AdvStory doesn't respond gestures anymore.

enableGestures()

Allows gesture events if disabled.

hideComponents()

Hides header, footer and story indicator. When gestures are not disabled, user can show hidden widgets by tapping screen.

showComponents()

Shows header, footer and story indicator.

pause()

Pauses the current story, this stops the timer and the story will not skip to the next content. Pauses the video if current content is a VideoContent. When gestures are not disabled, user can resume by tapping screen.

resume()

Resumes the current story, this starts the timer from last position and the story skips as usual. Resumes the video if current content is a VideoContent.

jumpTo(clusterIndex, storyIndex)

Jumps to the content at the given position.

toNextContent()

Skips to the next content if available. Otherwise skips to the next story or closes the story view.

toPreviousContent()

Skips to the previous content if available. Otherwise skips to the previous story or does nothing.

toNextStory()

Skips to the next story if available, otherwise closes the story view.

toPreviousStory()

Skips to the previous story if available, otherwise does nothing.

preloadMediaFile({ required String url, String? cacheKey, Map<String, String>?requestHeaders})

Useful when you want to extend AdvStory media load strategy. By default, [AdvStory] loads previous and next contents media in the background.
To see AdvStoryController in action go to example project.