Closed burhankhanzada closed 5 months ago
Get it work after looking at source code example/read_me.dart
file we need to add option explicitSubTypes
in morphy annotation.
import 'package:morphy_annotation/morphy_annotation.dart';
import 'package:morphy_test/student.dart';
part 'human.g.dart';
part 'human.morphy.dart';
@Morphy(generateJson: true, explicitSubTypes: [$Student])
abstract class $Human {
String get name;
int get age;
}
How to generate
changeTo_Subclass
method on superclass as described at https://pub.dev/packages/morphy#changetopart 'human.morphy.dart';
@morphy abstract class $Human { String get name; int get age; }
part of 'human.dart';
// ** // Generator: MorphyGenerator
// **
/// class Human extends $Human { final String name; final int age;
/// Human({ required this.name, required this.age, }); Human._({ required this.name, required this.age, }); String toString() => "(Human-name:${name.toString()}|age:${age.toString()})"; int get hashCode => hashObjects([name.hashCode, age.hashCode]); bool operator ==(Object other) => identical(this, other) || other is Human && runtimeType == other.runtimeType && name == other.name && age == other.age; Human copyWithHuman({ String Function()? name, int Function()? age, }) { return Human.( name: name == null ? this.name as String : name() as String, age: age == null ? this.age as int : age() as int, ); } }
extension $Human_changeTo_E on $Human { Human changeToHuman({ String Function()? name, int Function()? age, }) { return Human.( name: name == null ? this.name as String : name() as String, age: age == null ? this.age as int : age() as int, ); } }
enum Human$ { name, age }