MarkdownController class
A Markdown document for MarkdownView: it loads, decodes and searches the source like plain text (TextLinesController) and adds how it is shown.
viewMode picks Preview, Code or Split. Searching from Preview switches to Code, because matches are highlighted in the source. The reading position is one 0..1 ratio shared by every mode, so switching modes, split scrolling and a saved position all agree.
- Inheritance
-
- Object
- ChangeNotifier
- DocumentController
- TextLinesController
- MarkdownController
Constructors
-
MarkdownController({ReadingPosition? initialPosition, ValueChanged<
ReadingPosition> ? onPositionChanged, String? baseDirectory, MarkdownViewMode mode = MarkdownViewMode.preview}) -
Opens a document in
mode(Preview unless told otherwise).
Properties
- baseDirectory ↔ String?
-
Where relative image paths resolve from. Each loadFile sets it to that
file's folder, unless one was passed to the constructor.
getter/setter pair
- 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 setterinherited
- currentTextMatch → TextMatch?
-
The current match, if any.
no setterinherited
- 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
-
hasSelection
→ ValueListenable<
bool> -
Whether the reader has text selected, for enabling a Copy button
without rebuilding on every other change.
no setterinherited
- initialRatio → double
-
The saved position as a 0..1 ratio of the document.
no setter
- 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 pairinherited
- 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 setterinherited
-
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 setterinherited
- maxFileBytes → int
-
The largest file loadFile reads. Bigger files fail with
DocumentLoadError.tooLarge before anything is read.
no setterinherited
- maxZoom → double
-
The largest zoom.
no setterinherited
- minZoom → double
-
The smallest zoom.
no setterinherited
-
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
-
The place to save, as JSON-safe values: pass it back as
initialPositionto reopen there.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 setterinherited
-
searchState
→ ValueListenable<
DocumentSearchState> -
The current search, updated as it runs and as the reader steps
through its matches.
no setterinherited
- source → String
-
The whole source, for copying.
no setter
- stats → MarkdownStats
-
Counts for the loaded source, computed once per load.
no setter
- status → DocumentStatus
-
Whether the document is loading, ready or failed.
no setterinherited
- topLine → int
-
The line (from 0) at the top of the view; a search starts from here.
no setteroverride
-
viewMode
→ ValueNotifier<
MarkdownViewMode> -
How the document is shown.
final
- zoom → double
-
Scales the view's font size: the text reflows at the new size.
no setterinherited
- zoomStep → double
-
How much zoomIn and zoomOut change zoom by.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
allText(
) → Future< String> -
The document's whole text, for "copy all". Empty for a format with no
text to give (a scanned PDF, until it has been recognised).
inherited
-
clearSearch(
) → void -
Ends the search and removes its highlights.
inherited
-
clearSelection(
) → void -
Clears the selection. Does nothing until a view is showing the
document.
inherited
-
copyAllText(
) → Future< bool> -
Puts allText on the clipboard; false when the document has no text
or the clipboard refused it.
inherited
-
copySelection(
) → Future< bool> -
Puts selectedText on the clipboard. Returns false when nothing is
selected or the clipboard refused it, so the app can say so.
inherited
-
copyToClipboard(
String text) → Future< bool> -
Writes
textto the clipboard; false when it isn't available.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
numberis kept untilapplyPending.inherited -
dispose(
) → void -
Discards any resources used by the object.
override
-
goTo(
int number) → void -
Scrolls line
number(from 1) to the top of the source, showing it first when only the preview is up.override -
loadBytes(
Uint8List bytes) → Future< void> -
Checks
byteslook like text, then decodes them into lines.override -
loadFile(
String path) → Future< void> -
Loads the document at
path.override -
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
-
revealLine(
int lineIndex) → void -
The source view scrolls to the current match itself, as it listens to
this controller.
override
-
search(
String query) → void -
Finds
queryin the source; from Preview this shows the source first.override -
selectAll(
) → void -
Selects everything the view has laid out: all of a spreadsheet's used
range, but only the pages or lines built so far in a long text
document; use allText to copy a whole document.
inherited
-
selectedText(
) → String? -
What the reader has selected, as the text to paste; null when nothing
is selected. PDF, Word, plain text, Markdown and slides give the
selected words; a spreadsheet gives its cells as tab-separated rows.
inherited
-
setHasSelection(
bool value) → void -
For a format that works out its selected text on demand (selectedText
being costly): there is, or isn't, a selection.
inherited
-
setViewMode(
MarkdownViewMode mode) → void -
Shows the document in
mode. -
setZoom(
double zoom) → void -
Sets
zoom, clamped to minZoom..maxZoom.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
updateLineLocation(
int topLine) → void -
The reader is now at line
topLine(from 0).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
-
isMarkdownExtension(
String extension) → bool -
Whether
extension(with or without the dot) names a Markdown file.
Constants
- unitsPerLine → const double
- Source-equivalent offset per line in the saved position, so a saved offset doesn't depend on the font size or the mode it was read in.