PreloadStateMixin

Asynchronously preloading the state of a StatefulComponent on the server.


The PreloadStateMixin lets you asynchronously load the state of a StatefulComponent before it is rendered on the server during pre-rendering.

Usage

Start by adding the PreloadStateMixin on a StatefulComponents State class and implement the Future<T> preloadState() method.

dart
class MyStatefulComponent extends StatefulComponent { /* ... */ }

class MyState extends State<MyStatefulComponent> with PreloadStateMixin {

  @override
  Future<void> preloadState() async {
    /* ... */
  }
}

This method will only be executed on the server and will be called before initState(). It will defer initState() as well as building the component until the future returned by the method is completed.

Alternatives

On this page