Skip to content

Instantly share code, notes, and snippets.

@matanshukry
Created September 9, 2023 10:32
Show Gist options
  • Save matanshukry/7e84b692058092a4fc82bb15e7f50ea6 to your computer and use it in GitHub Desktop.
Save matanshukry/7e84b692058092a4fc82bb15e7f50ea6 to your computer and use it in GitHub Desktop.
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