Created
November 9, 2025 15:24
-
-
Save escamoteur/e92fc4b2a0aaf4d180f46110543c6706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ignore_for_file: unused_local_variable, unused_field | |
| class MyCallable<TParam, TReturn> { | |
| final TReturn _defaultValue; | |
| MyCallable(this._defaultValue); | |
| TReturn call([TParam? value]) { | |
| if (value != null) { | |
| print('MyCallable instance called with parameter: $value'); | |
| } else { | |
| print('MyCallable instance called without parameter'); | |
| } | |
| return _defaultValue; | |
| } | |
| } | |
| class Processor<R1, R2> { | |
| final R1 Function()? _callbackWithoutParam; | |
| final void Function() voidCallback; | |
| final void Function()? nullableCallBack; | |
| final void Function()? nullableCallBack2; | |
| Processor({ | |
| R1 Function()? callbackWithoutParam, | |
| this.nullableCallBack, | |
| this.nullableCallBack2, | |
| required this.voidCallback | |
| }) : _callbackWithoutParam = callbackWithoutParam; | |
| } | |
| void main() { | |
| var callable = MyCallable<String, String>('Default string result'); | |
| var callableNoParamVoid = MyCallable<void, void>('Default string result'); | |
| bool isActive=true; | |
| final handler = isActive ? callableNoParamVoid : null; | |
| Processor<String, bool>( | |
| callbackWithoutParam: callable, | |
| voidCallback: callable, | |
| nullableCallBack: callableNoParamVoid, | |
| nullableCallBack2: handler | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment