2023-01-29 16:04:15 +00:00
|
|
|
import 'package:example2/src/models.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
final stopwatch = Stopwatch()..start();
|
|
|
|
|
|
|
|
//var reflectedClass = reflect(Shape());
|
|
|
|
|
|
|
|
//reflectedClass.invoke(#draw, []);
|
|
|
|
|
|
|
|
//reflectedClass.invoke(Symbol('draw'), []);
|
|
|
|
|
|
|
|
print('Reflection executed in ${stopwatch.elapsed.inMilliseconds} ms');
|
|
|
|
stopwatch.stop();
|
|
|
|
|
2023-03-11 04:44:22 +00:00
|
|
|
//printAnnotationValue(String);
|
|
|
|
//printAnnotationValue(Shape);
|
|
|
|
//printAnnotationValue(Square);
|
2023-01-29 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Shape {
|
|
|
|
void draw() => print("Draw Shape");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Person('Will', 'Tom')
|
|
|
|
class Square {
|
|
|
|
void greetHii() {
|
|
|
|
print("Hii Welcome to flutter agency");
|
|
|
|
}
|
|
|
|
}
|
2023-03-11 04:44:22 +00:00
|
|
|
/*
|
2023-01-29 16:04:15 +00:00
|
|
|
void printAnnotationValue(final Type clazz) {
|
|
|
|
final DeclarationMirror clazzDeclaration = reflectClass(clazz);
|
|
|
|
final ClassMirror someAnnotationMirror = reflectClass(Person);
|
|
|
|
final annotationInstsanceMirror =
|
|
|
|
clazzDeclaration.metadata.where((d) => d.type == someAnnotationMirror);
|
|
|
|
if (annotationInstsanceMirror.isEmpty) {
|
|
|
|
print('No annotated class found');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final someAnnotationInstance =
|
|
|
|
(annotationInstsanceMirror.first.reflectee as Person);
|
|
|
|
print(someAnnotationInstance.firstName);
|
|
|
|
}
|
2023-03-11 04:44:22 +00:00
|
|
|
*/
|