renderPage method

String renderPage(
  1. PageRegistry registry,
  2. String component, {
  3. Object? props = const <String, dynamic>{},
  4. FlintComponent missingPage(
    1. String component
    )?,
})

Renders a registered page component to HTML.

Implementation

String renderPage(
  PageRegistry registry,
  String component, {
  Object? props = const <String, dynamic>{},
  FlintComponent Function(String component)? missingPage,
}) {
  final normalizedProps = switch (props) {
    FlintProps typed => typed.toJson(),
    Map<String, dynamic> map => map,
    Map map => map.map((key, value) => MapEntry(key.toString(), value)),
    _ => const <String, dynamic>{},
  };
  final builder = registry[component];
  final page = builder?.call(normalizedProps) ??
      missingPage?.call(component) ??
      _MissingServerPage(component);
  return render(page);
}