Line data Source code
1 : import 'package:collection/collection.dart'; 2 : import 'package:meta/meta.dart'; 3 : import 'package:widgetbook_generator/code_generators/properties/property.dart'; 4 : 5 : @immutable 6 : class FunctionProperty extends Property { 7 2 : FunctionProperty({ 8 : required String key, 9 : required this.functionName, 10 : this.parameters = const <String>[], 11 2 : }) : super( 12 : key: key, 13 : ); 14 : 15 : final String functionName; 16 : final List<String> parameters; 17 : 18 1 : String parametersToCode() { 19 2 : return parameters.join(', '); 20 : } 21 : 22 1 : @override 23 : String valueToCode() { 24 1 : final parameters = parametersToCode(); 25 2 : return '($parameters) => $functionName($parameters)'; 26 : } 27 : 28 1 : @override 29 : bool operator ==(Object other) { 30 : if (identical(this, other)) return true; 31 1 : final listEquals = const DeepCollectionEquality().equals; 32 : 33 1 : return other is FunctionProperty && 34 3 : other.key == key && 35 3 : other.functionName == functionName && 36 2 : listEquals(other.parameters, parameters); 37 : } 38 : 39 0 : @override 40 : int get hashCode => 41 0 : functionName.hashCode ^ parameters.hashCode ^ key.hashCode; 42 : }