How to check if a parameter initializes super class field in Dart?

41 Views Asked by At

I would like this code below to print

this.dog;
super.animal;
Easy!

But it doesn't

import 'dart:mirrors';

class Animal {
  final String animal;

  Animal({required this.animal});
}

class Dog extends Animal {
  final String dog;

  Dog({required this.dog, required super.animal});
}

void main () {

  final classMirror = reflectClass(Dog);
  for (final entry in classMirror.declarations.entries) {
    final declaration = entry.value;
    if (declaration is! MethodMirror) continue;
    final parametersList = declaration.parameters;
    for (final parameter in parametersList) {
      final parameterName = MirrorSystem.getName(parameter.simpleName);
      // check if super parameter like super.id
      final isSuper = false; /// how to do this?
      if (isSuper) {
        print("super.$parameterName;");
      } else {
        print("this.$parameterName;");
      }
    }
  }
  print("Easy!");
}
0

There are 0 best solutions below