of static method

CLTheme of(
  1. BuildContext context
)

Implementation

static CLTheme of(BuildContext context) {
  final isDark = Theme.of(context).brightness == Brightness.dark;

  // 1. Cerca il provider generico (nuovo, consigliato)
  // listen:false — la sostituzione del provider richiede ricostruzione del MaterialApp,
  // quindi non serve sottoscrivere qui (evita rebuild a cascata su notifyListeners).
  try {
    final tp = Provider.of<CLThemeProvider>(context, listen: false);
    return isDark ? tp.darkTheme : tp.lightTheme;
  } catch (_) {}

  // 2. Fallback: cerca il vecchio ModuleThemeProvider (retrocompatibilità)
  // listen:false — stesso motivo: lookup dati tema, non flusso reattivo.
  try {
    // ignore: deprecated_member_use_from_same_package
    final mp = Provider.of<ModuleThemeProvider>(context, listen: false);
    return isDark ? mp.darkTheme : mp.lightTheme;
  } catch (_) {}

  // 3. Default built-in
  return isDark ? dark : light;
}