Line data Source code
1 : import 'package:analyzer/dart/element/element.dart'; 2 : import 'package:widgetbook_generator/extensions/element_extensions.dart'; 3 : import 'package:widgetbook_generator/models/widgetbook_data.dart'; 4 : 5 : /// Contains the data of a Story 6 : class WidgetbookStoryData extends WidgetbookData { 7 : /// Creates a new instance of [WidgetbookStoryData] 8 : /// 9 : /// [name] is defined as the identifier of the annotated element 10 : /// [importStatement] is the statement required to include the annotated 11 : /// element in the Widgetbook 12 : /// [dependencies] are the import statements defined in the file in which the 13 : /// annotation is used 14 : /// [storyName] is the name of the Story provided as a parameter of the 15 : /// WidgetbookStory annotation 16 : /// [widgetName] is the String version of the Widget type 17 1 : WidgetbookStoryData({ 18 : required String name, 19 : required String importStatement, 20 : required this.typeDefinition, 21 : required List<String> dependencies, 22 : required this.storyName, 23 : required this.widgetName, 24 1 : }) : super( 25 : name: name, 26 : importStatement: importStatement, 27 : dependencies: dependencies, 28 : ); 29 : 30 : /// Obtains a [WidgetbookStoryData] object from classes provided by the 31 : /// StoryResolver 32 0 : factory WidgetbookStoryData.fromResolver( 33 : Element element, 34 : Element typeElement, 35 : String storyName, 36 : String widgetName, 37 : ) { 38 0 : return WidgetbookStoryData( 39 0 : name: element.name!, 40 0 : importStatement: element.importStatement, 41 0 : typeDefinition: typeElement.importStatement, 42 0 : dependencies: typeElement.dependencies, 43 : storyName: storyName, 44 : widgetName: widgetName, 45 : ); 46 : } 47 : 48 : /// transforms the serializable map into a [WidgetbookStoryData] object. 49 0 : factory WidgetbookStoryData.fromMap(Map<String, dynamic> map) { 50 0 : return WidgetbookStoryData( 51 0 : name: map['name'] as String, 52 0 : importStatement: map['importStatement'] as String, 53 0 : typeDefinition: map['typeDefinition'] as String, 54 0 : dependencies: List<String>.from(map['dependencies'] as Iterable), 55 0 : storyName: map['storyName'] as String, 56 0 : widgetName: map['widgetName'] as String, 57 : ); 58 : } 59 : 60 : /// The name of the story. 61 : /// This name will be displayed in the navigation panel of the Widgetbook 62 : /// user interface 63 : final String storyName; 64 : 65 : /// The String version of the Widget's type 66 : /// [widgetName] will be displayed as a WidgetElement in the Widgetbook. 67 : final String widgetName; 68 : 69 : final String typeDefinition; 70 : 71 0 : @override 72 : Map<String, dynamic> toMap() { 73 0 : return <String, dynamic>{ 74 0 : 'name': name, 75 0 : 'importStatement': importStatement, 76 0 : 'typeDefinition': typeDefinition, 77 0 : 'dependencies': dependencies, 78 0 : 'storyName': storyName, 79 0 : 'widgetName': widgetName, 80 : }; 81 : } 82 : }