flutter_prerender library

Prerender a Flutter web app to static, crawlable HTML for SEO.

The public API is split into small, independently testable pieces:

Most users invoke the bundled flutter_prerender command rather than the library directly; see runCli.

Classes

CapturedPage
The raw material recovered from one loaded route: the document title, the serialised Flutter semantics DOM, and the app's rendered text.
ContentNode
A single piece of crawlable content recovered from a Flutter semantics tree.
FailedRoute
A route whose capture failed outright, for example a same-origin link to a PDF, an image, or some other non-Flutter asset that a crawl reached.
HeadingContent
A heading recovered from the semantics tree (<h1> .. <h6>).
HtmlBuilder
Serialises recovered ContentNodes and RouteMeta into a complete, static, crawlable HTML document.
ImageContent
An image recovered from the semantics tree, carrying its alternative text.
LinkContent
A hyperlink recovered from the semantics tree (<a href>).
PageCapturer
Loads a route in a real browser and captures its content.
ParagraphContent
A block of body text recovered from the semantics tree (<p>).
ParityGuard
Compares prerendered body text against the text a Flutter app renders and reports any divergence.
ParityReport
The result of comparing the prerendered text against Flutter's own accessibility text.
PrerenderConfig
The fully resolved configuration for a prerender run.
PrerenderEngine
Drives the end-to-end prerender: capture each route, recover content, build HTML, run the parity guard, write files, and emit a sitemap.
PrerenderResult
The outcome of a complete prerender run.
PuppeteerCapturer
A PageCapturer backed by package:puppeteer and headless Chrome.
RouteMeta
SEO metadata for a single prerendered route.
RouteResult
The outcome of prerendering a single route.
RouteSpec
A route to prerender together with its per-route SEO metadata.
SemanticsExtractor
Recovers an ordered list of ContentNodes from the HTML of a Flutter semantics tree (<flt-semantics-host> and its descendants).
SitemapEntry
A single <url> entry in a sitemap.
StaticServer
A minimal static file server used to serve a flutter build web directory to the headless browser during prerendering.

Constants

defaultConfigFile → const String
The default config file name looked up in the working directory.
packageVersion → const String
The published version of the package. Kept in sync with pubspec.yaml.

Functions

buildParser() → ArgParser
Builds the command-line argument parser for the tool.
buildRobotsTxt({String? sitemapUrl}) String
Builds a robots.txt that allows crawling and, when sitemapUrl is given, points crawlers at the sitemap.
buildSitemap(Iterable<SitemapEntry> entries) String
Builds a sitemap.xml document from entries.
contentTypeFor(String filePath) String
Returns the MIME type for filePath based on its extension, defaulting to application/octet-stream.
discoverRoutes(Iterable<String> hrefs, {required Set<String> known, required int limit, String? origin}) List<String>
Selects new same-origin routes discovered from a page's link hrefs.
joinUrl(String baseUrl, String path) String
Joins a site baseUrl and a route path into a single absolute URL, collapsing the slash between them.
normalizeRoute(String raw, {int? lineNumber}) String
Normalises a single route path.
parseRoutesFile(String content) List<String>
Parses the contents of a plain-text routes file into normalised route paths.
resolveWithinRoot(String rootDir, String requestPath) String?
Resolves requestPath against rootDir, returning an absolute file path, or null if the path would escape rootDir (a traversal attempt).
runCli(List<String> args, {StringSink? out, StringSink? err, PageCapturer capturerFactory(PrerenderConfig config)?}) Future<int>
Parses args, runs the prerender, and returns a process exit code.
sameOriginRoute(String href, {String? origin}) String?
Resolves a discovered link href to a same-origin route path, or returns null when the link is not a crawlable page on this site.

Exceptions / Errors

BrowserLaunchException
Thrown when the headless browser cannot be launched (for example, when no Chrome/Chromium executable can be found or downloaded).
BuildNotFoundException
Thrown when the Flutter web build directory is missing or incomplete.
ConfigException
Thrown when a configuration file or route list cannot be parsed.
PrerenderException
Base class for all errors thrown by flutter_prerender.
RouteCaptureException
Thrown when a route cannot be captured, for example when the page never produces a Flutter semantics tree within the configured timeout.