Line data Source code
1 : import 'package:meta/meta.dart'; 2 : 3 : import 'package:widgetbook_generator/code_generators/instances/base_instance.dart'; 4 : import 'package:widgetbook_generator/code_generators/instances/double_instance.dart'; 5 : import 'package:widgetbook_generator/code_generators/instances/string_instance.dart'; 6 : 7 : /// A property which is set when a new instance is created 8 : @immutable 9 : class Property { 10 4 : const Property({ 11 : required this.key, 12 : required this.instance, 13 : }); 14 : 15 4 : Property.string({ 16 : required this.key, 17 : required String value, 18 4 : }) : instance = StringInstance.value(value); 19 : 20 4 : Property.double({ 21 : required this.key, 22 : required double value, 23 4 : }) : instance = DoubleInstance.value(value); 24 : 25 : final String key; 26 : final BaseInstance instance; 27 : 28 3 : String _instanceToCode() => instance.toCode(); 29 : 30 1 : String _nameToCode() { 31 1 : return key; 32 : } 33 : 34 1 : String toCode() { 35 1 : final value = _instanceToCode(); 36 1 : final name = _nameToCode(); 37 1 : return '$name: $value'; 38 : } 39 : 40 5 : @override 41 : bool operator ==(Object other) { 42 : if (identical(this, other)) return true; 43 : 44 32 : return other is Property && other.key == key && other.instance == instance; 45 : } 46 : 47 1 : @override 48 5 : int get hashCode => key.hashCode ^ instance.hashCode; 49 : 50 1 : @override 51 3 : String toString() => 'Property(key: $key, instance: $instance)'; 52 : }