of static method

  1. @useResult
FThemeData of(
  1. BuildContext context
)

Returns the current FThemeData, or FThemes.zinc.light if there is no ancestor FTheme.

It is recommended to use the terser ThemeBuildContext.theme getter instead.

Troubleshooting:

FTheme.of always returns FThemes.zinc.light

One of the most common causes is calling FTheme.of in the same context which FTheme was declared. To fix this, move the call to FTheme.of to a descendant widget.

✅ Do:

class Parent extends StatelessWidget {
  @override
  Widget build(BuildContext context) => FTheme(
     data: FThemes.zinc.light,
     child: Child(),
   );
 }

 class Child extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     final FThemeData theme = FTheme.of(context);
     return const SomeWidget(theme: theme);
   }
 }

❌ Do not:

class Parent extends StatelessWidget {
  @override
  Widget build(BuildContext context) => FTheme(
     data: FThemes.zinc.light,
     child: SomeWidget(
       theme: FTheme.of(context), // Whoops!
     ),
   );
 }

Implementation

@useResult
static FThemeData of(BuildContext context) {
  final theme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
  return theme?.data ?? FThemes.zinc.light;
}