Skip to content

Instantly share code, notes, and snippets.

@VB10
Created December 15, 2019 21:50
Show Gist options
  • Select an option

  • Save VB10/e6bec3dbf974082e411f8ad641cfaa02 to your computer and use it in GitHub Desktop.

Select an option

Save VB10/e6bec3dbf974082e411f8ad641cfaa02 to your computer and use it in GitHub Desktop.
Reflaction Sample Method
void getSample<T>() {
ClassMirror classMirror = reflector.reflectType(T);
print(classMirror);
var hello1 = classMirror.newInstance("", []);
if (hello1 is Hello) {
hello1.age = 15;
hello1.message = "oke";
hello1.printName();
setState(() {
hello = hello1;
});
}
}
void getSample2<T>() {
ClassMirror classMirror = reflector.reflectType(T);
print(classMirror);
var hello2 = classMirror.newInstance("setMessage", ["hello2"]);
if (hello2 is Hello) {
hello2.printName();
setState(() {
hello = hello2;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment