Created
December 15, 2019 21:50
-
-
Save VB10/e6bec3dbf974082e411f8ad641cfaa02 to your computer and use it in GitHub Desktop.
Reflaction Sample Method
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
| 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