Created
September 9, 2023 10:32
-
-
Save matanshukry/7e84b692058092a4fc82bb15e7f50ea6 to your computer and use it in GitHub Desktop.
This file contains 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
typedef GenMethod<T> = String Function(T value); | |
class CustomValue { | |
final String data1; | |
final String data2; | |
CustomValue(this.data1, this.data2); | |
} | |
GenMethod<int> getNumToString() { | |
return (value) => value.toString(); | |
} | |
GenMethod<CustomValue> getCustomValueToString() { | |
return (value) => '${value.data1} ${value.data2}'; | |
} | |
class MyData<T> { | |
final GenMethod<T> method; | |
MyData(this.method); | |
} | |
String dataToString(MyData<dynamic> anyData, dynamic value) { | |
return anyData.method(value); | |
} | |
void main() { | |
final datas = [ | |
MyData<int>(getNumToString()), | |
MyData<CustomValue>(getCustomValueToString()), | |
]; | |
print(datas.runtimeType); | |
final data = datas[0] as MyData<int>; | |
print(data.runtimeType); | |
final value = dataToString(data, 2); | |
print(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment