2

this is flutter rsocket-dart code.

https://github.com/rsocket/rsocket-dart/blob/master/lib/route/reflection.dart

but, I cant't to use this library in flutter, because this package use 'dart:mirrors' packages.
So, I want to change this code.

but, I very very low level... I can't to understood this code...

import 'dart:mirrors';

import '../rsocket.dart';
import 'package:collection/collection.dart' show IterableExtension;

RSocketService? getRSocketServiceAnnotation(dynamic instance) {
  final DeclarationMirror clazzDeclaration = reflectClass(instance.runtimeType);
  final classMirror = reflectClass(RSocketService);
  final annotationInstanceMirror =
      clazzDeclaration.metadata.firstWhereOrNull((d) => d.type == classMirror);
  if (annotationInstanceMirror == null) {
    print('Annotation is not on this class');
    return null;
  }
  return annotationInstanceMirror.reflectee as RSocketService?;
}

How can I change this code to not use mirror?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Too
  • 115
  • 1
  • 9

1 Answers1

0

Have you tried using the reflectable package?

However, unlike dart:mirror reflectable uses the "code generation" you have to run build_runner to generate the necessary code.

flutter pub run build_runner watch

Here is an example project that I created.

https://github.com/dinbtechit/flutter_reflection_test

Dinesh
  • 1,711
  • 2
  • 20
  • 41