@@ -29,16 +29,17 @@ class DecoderForClassA extends Decoder<A> {
2929 @override
3030 A read (DartObject obj) {
3131 final id = obj.read <int >(fieldName: 'id' );
32- final names = obj.readSet < String >(fieldName: 'names' );
33- final numbers = obj.readList < num >(fieldName: 'numbers' );
32+ final names = obj.read < Set < String > >(fieldName: 'names' );
33+ final numbers = obj.read < List < num > >(fieldName: 'numbers' );
3434 return A (id: id, names: names, numbers: numbers);
3535 }
3636}
3737
3838const decoderForA = DecoderForClassA ();
3939
4040Future <void > main () async {
41- final library = await resolveSource (
41+ print ('\n Reading library <example>\n ' );
42+ final lib = await resolveSource (
4243 r'''
4344 library example;
4445
@@ -54,8 +55,9 @@ Future<void> main() async {
5455 final int id = 124;
5556 final Map<String, int> score = {'Adam': 4, 'Moira': 7};
5657 final isValid = true;
57-
58+ final List<num> numbers = [7, 77.7];
5859 final a = const A(id: 42, names: {'Andy', 'Eva'}, numbers: [42, 3.14]);
60+ final num number = 3;
5961 }
6062
6163 ''' ,
@@ -64,9 +66,13 @@ Future<void> main() async {
6466 );
6567
6668 /// Reading libraries.
67- print ('\n Reading library <example>\n ' );
6869
69- final lib = library! ;
70+ if (lib == null ) {
71+ print ('Could not read library!' );
72+ return ;
73+ }
74+
75+ print (Reader .info);
7076
7177 final idObj = lib.classes[1 ].fields[0 ].computeConstantValue ();
7278 final id = idObj? .read <int >();
@@ -85,11 +91,25 @@ Future<void> main() async {
8591 'Reading a ${'bool' .style (Ansi .green )}: $isValid ${isValid .runtimeType }\n ' ,
8692 );
8793
94+ final numbersObj = lib.classes[1 ].fields[3 ].computeConstantValue ();
95+ final numbers = numbersObj? .read <List <num >>();
96+ print (
97+ 'Reading a ${'List<num>' .style (Ansi .green )}: $numbers ${numbers .runtimeType }\n ' ,
98+ );
99+
88100 /// Adding a decoder:
89101 Reader .addDecoder (decoderForA);
90102
91- final aObj = lib.classes[1 ].fields[3 ].computeConstantValue ();
103+ final aObj = lib.classes[1 ].fields[4 ].computeConstantValue ();
92104 final a = aObj? .read <A >();
93105
94- print ('Reading a constant with type ${'A' .style (Ansi .green )}: $a ' );
106+ print ('Reading a constant with type ${'A' .style (Ansi .green )}: $a \n ' );
107+
108+ final numberObj = lib.classes[1 ].fields[5 ].computeConstantValue ();
109+ final number = numberObj? .read ();
110+
111+ print ('Reading a constant with type ${'num' .style (Ansi .green )}: $number \n ' );
112+
113+ print (Reader .info);
114+ return ;
95115}
0 commit comments