Skip to content

Commit

Permalink
fix: added error when WidgetbookTheme is used on non-function code el…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
jenshor committed Mar 23, 2022
1 parent 4f9f488 commit b7e65c2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/widgetbook_generator/lib/resolvers/theme_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ class ThemeResolver extends GeneratorForAnnotation<WidgetbookTheme> {
);
}

if (element.kind != ElementKind.FUNCTION ||
!(element as FunctionElement).isStatic) {
throw InvalidGenerationSourceError(
'The $WidgetbookTheme annotation cannot be applied to static '
'functions.',
element: element,
);
}

final isDefault = annotation.read('isDefault').boolValue;
final name = annotation.read('name').stringValue;

final themeData = WidgetbookThemeData(
name: element.name!,
name: element.name,
importStatement: element.importStatement,
dependencies: element.dependencies,
isDefault: isDefault,
Expand Down

0 comments on commit b7e65c2

Please sign in to comment.