debugCheckHasFluentTheme function

bool debugCheckHasFluentTheme(
  1. BuildContext context, [
  2. bool check = true
])

Asserts that the given context has a FluentTheme ancestor.

To call this function, use the following pattern, typically in the relevant Widget's build method:

assert(debugCheckHasFluentTheme(context));

Does nothing if asserts are disabled. Always returns true.

Implementation

bool debugCheckHasFluentTheme(BuildContext context, [bool check = true]) {
  assert(() {
    if (FluentTheme.maybeOf(context) == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('A FluentTheme widget is necessary to draw this layout.'),
        ErrorHint(
          'To introduce a FluentTheme widget, you can either directly '
          'include one, or use a widget that contains FluentTheme itself, '
          'such as FluentApp',
        ),
        ...context.describeMissingAncestor(expectedAncestorType: FluentTheme),
      ]);
    }
    return true;
  }());
  return true;
}