addStoryToFolder method

void addStoryToFolder(
  1. Folder? folder,
  2. WidgetbookStoryData story
)

Implementation

void addStoryToFolder(
  Folder? folder,
  WidgetbookStoryData story,
) {
  final widgetName = story.widgetName;

  folder ??= rootFolder;

  final widgets = folder.widgets;
  if (!widgets.containsKey(widgetName)) {
    widgets.putIfAbsent(
      widgetName,
      () => Widget(widgetName),
    );
  }

  // TODO do we need to check if a story with that name already exist?
  // it might happen by copy and pasting that stories are duplicated.
  widgets[widgetName]!.stories.add(story);
}