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