PlainTextController class

Loads a plain-text document for PlainTextView: its lines, line wrap, zoom, search and the scroll position.

Text is decoded as UTF-8, or after a UTF-16 byte order mark, falling back to Latin-1. The position is {scroll_offset, line} (line, the top visible line, once the view has measured its lines).

Inheritance

Constructors

PlainTextController({ReadingPosition? initialPosition, ValueChanged<ReadingPosition>? onPositionChanged, bool wrap = true})
Reopens at the scroll offset saved in initialPosition, if any.

Properties

canZoomIn → bool
Whether zoomIn would zoom in.
no setterinherited
canZoomOut → bool
Whether zoomOut would zoom out.
no setterinherited
currentMatch → int
Which of matches is current, or -1 when there are none.
no setter
currentTextMatch → TextMatch?
The current match, if any.
no setter
error → DocumentLoadError?
Why the document couldn't be loaded; null unless status is DocumentStatus.failed.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
initialScrollOffset ↔ double
Where the view scrolls to once laid out (from the saved position). Settable until then, for an app that reads the saved position after creating the controller.
getter/setter pair
isDisposed → bool
Whether dispose has been called. A load that finishes afterwards discards its result.
no setterinherited
isLoaded → bool
True once loading has finished, successfully or not.
no setterinherited
lines → List<String>
The document's lines.
no setter
location → ValueListenable<DocumentLocation>
Where the reader is, updated as they move: listen to it for a "page 3 of 12" display without rebuilding on every other change.
no setterinherited
matches → List<TextMatch>
Every occurrence of searchQuery, in order.
no setter
maxFileBytes → int
The largest file loadFile reads. Bigger files fail with DocumentLoadError.tooLarge before anything is read.
no setteroverride
maxZoom → double
The largest zoom.
no setteroverride
minZoom → double
The smallest zoom.
no setteroverride
onPositionChanged → ValueChanged<ReadingPosition>?
Called as the reader moves through the document, with the position to save. Debouncing and storage are up to the app.
finalinherited
position → ReadingPosition
line is there once the view has measured its lines.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
searchQuery → String
The text being searched for; empty when there's no search.
no setter
searchState → ValueListenable<DocumentSearchState>
The current search, updated as it runs and as the reader steps through its matches.
no setterinherited
status → DocumentStatus
Whether the document is loading, ready or failed.
no setterinherited
wrap ↔ bool
Whether long lines wrap; when false each line scrolls sideways.
getter/setter pair
zoom → double
Scales PlainTextView.fontSize: the text reflows at the new size.
no setteroverride
zoomStep → double
How much zoomIn and zoomOut change zoom by.
no setteroverride

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clearSearch() → void
Ends the search and removes its highlights.
inherited
deferGoTo(int number) → void
For a format's controller: goTo can't move yet (the document isn't loaded, or no view has laid it out), so number is kept until applyPending.
inherited
dispose() → void
Discards any resources used by the object.
override
goTo(int number) → void
Scrolls line number (from 1) to the top.
override
loadBytes(Uint8List bytes) → Future<void>
Checks bytes look like text, then decodes them into lines.
override
loadFile(String path) → Future<void>
Loads the document at path.
inherited
markFailed(DocumentLoadError error) → void
For a format's controller, or an app whose own read of the file failed: the document can't be shown, because of error.
inherited
markLoading() → void
For a format's controller: loading has started.
inherited
markReady() → void
For a format's controller: the document is loaded.
inherited
nextMatch() → void
Shows the next match, wrapping round after the last.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
previousMatch() → void
Shows the previous match, wrapping round before the first.
override
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
reportPosition() → void
Reports position to onPositionChanged.
inherited
Finds every occurrence of query (ignoring case) and shows the first one at or below the top of the view.
override
setZoom(double zoom) → void
Sets zoom, clamped to minZoom..maxZoom.
override
toString() → String
A string representation of this object.
inherited
updateLocation(DocumentLocation location) → void
For a format's controller: the reader is now at location.
inherited
updateSearch(DocumentSearchState state) → void
For a format's controller: the search is now state.
inherited
zoomIn() → void
Zooms in one step.
inherited
zoomOut() → void
Zooms out one step.
inherited

Operators

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

Static Methods

looksBinary(Uint8List bytes) → bool
Whether bytes look like a binary file rather than text; see looksLikeBinary, which this forwards to.

Constants

maxBytes → const int
Above this size a file is refused rather than read into memory in one pass.