hookBuildInitialWidget method

  1. @protected
  2. @visibleForOverriding
Widget? hookBuildInitialWidget()
inherited

Called right after hookInitState, to give the application code a chance to provide an alternative Widget to render while the widget is being initialized.

This is useful when the primary ZML relies on data that requires a delayed initialization. For example - data that needs to be downloaded from the internet.

When an initial widget is provided, either by this function or by providing initial ZML in an _INITIAL_ZML constant in the widget class - it is displayed instead of the primary ZML until hookPrepare returns.

If this hook returns a non-null value then the _INITIAL_ZML constant is ignored.

Example for using hookBuildInitialWidget:

@EzWidget()
class HomeState extends _EzStateBase {
  Widget? hookBuildInitialWidget() => Container(child: Text("Loading..."));

  static const String _ZML = """
    <Container>
      <Text>Loaded!</Text>
    </Container>
  """
}

Example for using _INITIAL_ZML:

@EzWidget()
class HomeState extends _EzStateBase {
  static const String _INITIAL_ZML = """
    <Container>
      <Text>Loading...</Text>
    </Container>
  """

  static const String _ZML = """
    <Container>
      <Text>Loaded!</Text>
    </Container>
  """
}

It is possible to initialize _INITIAL_ZML from a global constant (to have consistent behavior across multiple widgets without effort), or to use one of the built-in ZML snippets provided by this component, for example:

@EzWidget()
class HomeState extends _EzStateBase {
  static const String _INITIAL_ZML = INITIAL_ZML_LOADING;

  static const String _ZML = """
    <Container>
      <Text>Loaded!</Text>
    </Container>
  """
}

Implementation

/// class HomeState extends _EzStateBase {
    ///   Widget? hookBuildInitialWidget() => Container(child: Text("Loading..."));
    ///
    ///   static const String _ZML = """
    ///     <Container>
    ///       <Text>Loaded!</Text>
    ///     </Container>
    ///   """
    /// }
/// ```
    ///
    /// Example for using _INITIAL_ZML:
///
/// ```dart
/// @EzWidget()
    /// class HomeState extends _EzStateBase {
    ///   static const String _INITIAL_ZML = """
    ///     <Container>
    ///       <Text>Loading...</Text>
    ///     </Container>
    ///   """
    ///
    ///   static const String _ZML = """
    ///     <Container>
    ///       <Text>Loaded!</Text>
    ///     </Container>
    ///   """
    /// }
/// ```
    ///
    /// It is possible to initialize _INITIAL_ZML from a global constant (to
    /// have consistent behavior across multiple widgets without effort), or
    /// to use one of the built-in ZML snippets provided by this component,
/// for example:
///
/// ```dart
/// @EzWidget()
    /// class HomeState extends _EzStateBase {
    ///   static const String _INITIAL_ZML = INITIAL_ZML_LOADING;
    ///
    ///   static const String _ZML = """
    ///     <Container>
    ///       <Text>Loaded!</Text>
    ///     </Container>
    ///   """
    /// }
/// ```
@protected
@visibleForOverriding
Widget? hookBuildInitialWidget() {
	return null;
}