of static method

ResponsiveData of(
  1. BuildContext context, {
  2. ScalifyAspect? aspect,
})

Accesses the nearest ResponsiveData and registers a dependency. Uses aspect to listen only to specific changes if granular notifications are enabled.

Implementation

static ResponsiveData of(BuildContext context, {ScalifyAspect? aspect}) {
  final inherited =
      context.dependOnInheritedWidgetOfExactType<_InheritedScalify>();

  // Fallback: no provider above in the tree
  if (inherited == null) {
    final provWidget =
        context.findAncestorWidgetOfExactType<ScalifyProvider>();
    final cfg = provWidget?.config ?? const ScalifyConfig();
    return ResponsiveData.fromMediaQuery(MediaQuery.maybeOf(context), cfg);
  }

  // If granular notifications disabled, just return data directly.
  if (!inherited.data.config.enableGranularNotifications) {
    return inherited.data;
  }

  // If caller provided an aspect, subscribe to it; otherwise return data.
  if (aspect == null) {
    return inherited.data;
  }

  return InheritedModel.inheritFrom<_InheritedScalify>(
    context,
    aspect: aspect,
  )!
      .data;
}