2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- // @dart=2.9
6
-
7
5
import 'package:collection/collection.dart' ;
8
6
import 'package:flutter/foundation.dart' ;
9
7
import 'package:vm_service/vm_service.dart' ;
@@ -22,12 +20,12 @@ part 'instance_details.freezed.dart';
22
20
typedef Setter = Future <void > Function (String newValue);
23
21
24
22
@freezed
25
- abstract class PathToProperty with _$PathToProperty {
23
+ class PathToProperty with _$PathToProperty {
26
24
const factory PathToProperty .listIndex (int index) = ListIndexPath ;
27
25
28
26
// TODO test that mutating a Map does not collapse previously expanded keys
29
27
const factory PathToProperty .mapKey ({
30
- @ required @nullable String ref,
28
+ required String ? ref,
31
29
}) = MapKeyPath ;
32
30
33
31
/// Must not depend on [InstanceRef] and its ID, as they may change across
@@ -39,13 +37,13 @@ abstract class PathToProperty with _$PathToProperty {
39
37
/// an object can have multiple properties with the same name (private properties
40
38
/// defined in different libraries)
41
39
const factory PathToProperty .objectProperty ({
42
- @ required String name,
40
+ required String name,
43
41
44
42
/// Path to the class/mixin that defined this property
45
- @ required String ownerUri,
43
+ required String ownerUri,
46
44
47
45
/// Name of the class/mixin that defined this property
48
- @ required String ownerName,
46
+ required String ownerName,
49
47
}) = PropertyPath ;
50
48
51
49
factory PathToProperty .fromObjectField (ObjectField field) {
@@ -58,21 +56,21 @@ abstract class PathToProperty with _$PathToProperty {
58
56
}
59
57
60
58
@freezed
61
- abstract class ObjectField with _$ObjectField {
59
+ class ObjectField with _$ObjectField {
62
60
factory ObjectField ({
63
- @ required String name,
64
- @ required bool isFinal,
65
- @ required String ownerName,
66
- @ required String ownerUri,
67
- @ required @nullable Result <InstanceRef > ref,
61
+ required String name,
62
+ required bool isFinal,
63
+ required String ownerName,
64
+ required String ownerUri,
65
+ required Result <InstanceRef > ref,
68
66
69
67
/// An [EvalOnDartLibrary] that can access this field from the owner object
70
- @ required EvalOnDartLibrary eval,
68
+ required EvalOnDartLibrary eval,
71
69
72
70
/// Whether this field was defined by the inspected app or by one of its dependencies
73
71
///
74
72
/// This is used by the UI to hide variables that are not useful for the user.
75
- @ required bool isDefinedByDependency,
73
+ required bool isDefinedByDependency,
76
74
}) = _ObjectField ;
77
75
78
76
ObjectField ._();
@@ -81,65 +79,63 @@ abstract class ObjectField with _$ObjectField {
81
79
}
82
80
83
81
@freezed
84
- abstract class InstanceDetails with _$InstanceDetails {
82
+ class InstanceDetails with _$InstanceDetails {
85
83
InstanceDetails ._();
86
84
87
- @Assert ('instanceRefId == null' )
88
85
factory InstanceDetails .nill ({
89
- String instanceRefId,
90
- @required @nullable Setter setter,
86
+ required Setter ? setter,
91
87
}) = NullInstance ;
92
88
93
89
factory InstanceDetails .boolean (
94
90
String displayString, {
95
- @ required String instanceRefId,
96
- @ required @nullable Setter setter,
91
+ required String instanceRefId,
92
+ required Setter ? setter,
97
93
}) = BoolInstance ;
98
94
99
95
factory InstanceDetails .number (
100
96
String displayString, {
101
- @ required String instanceRefId,
102
- @ required @nullable Setter setter,
97
+ required String instanceRefId,
98
+ required Setter ? setter,
103
99
}) = NumInstance ;
104
100
105
101
factory InstanceDetails .string (
106
102
String displayString, {
107
- @ required String instanceRefId,
108
- @ required @nullable Setter setter,
103
+ required String instanceRefId,
104
+ required Setter ? setter,
109
105
}) = StringInstance ;
110
106
111
107
factory InstanceDetails .map (
112
108
List <InstanceDetails > keys, {
113
- @ required int hash,
114
- @ required String instanceRefId,
115
- @ required @nullable Setter setter,
109
+ required int hash,
110
+ required String instanceRefId,
111
+ required Setter ? setter,
116
112
}) = MapInstance ;
117
113
118
114
factory InstanceDetails .list ({
119
- @ required @nullable int length,
120
- @ required int hash,
121
- @ required String instanceRefId,
122
- @ required @nullable Setter setter,
115
+ required int length,
116
+ required int hash,
117
+ required String instanceRefId,
118
+ required Setter ? setter,
123
119
}) = ListInstance ;
124
120
125
121
factory InstanceDetails .object (
126
122
List <ObjectField > fields, {
127
- @ required String type,
128
- @ required int hash,
129
- @ required String instanceRefId,
130
- @ required @nullable Setter setter,
123
+ required String type,
124
+ required int hash,
125
+ required String instanceRefId,
126
+ required Setter ? setter,
131
127
132
128
/// An [EvalOnDartLibrary] associated with the library of this object
133
129
///
134
130
/// This allows to edit private properties.
135
- @ required EvalOnDartLibrary evalForInstance,
131
+ required EvalOnDartLibrary evalForInstance,
136
132
}) = ObjectInstance ;
137
133
138
134
factory InstanceDetails .enumeration ({
139
- @ required String type,
140
- @ required String value,
141
- @ required @nullable Setter setter,
142
- @ required String instanceRefId,
135
+ required String type,
136
+ required String value,
137
+ required Setter ? setter,
138
+ required String instanceRefId,
143
139
}) = EnumInstance ;
144
140
145
141
bool get isExpandable {
@@ -156,15 +152,29 @@ abstract class InstanceDetails with _$InstanceDetails {
156
152
object: (instance) => instance.fields.isNotEmpty,
157
153
);
158
154
}
155
+
156
+ // Since `nil` doesn't have those properties, we are manually exposing them
157
+ String ? get instanceRefId {
158
+ return map (
159
+ nill: (_) => null ,
160
+ boolean: (a) => a.instanceRefId,
161
+ number: (a) => a.instanceRefId,
162
+ string: (a) => a.instanceRefId,
163
+ map: (a) => a.instanceRefId,
164
+ list: (a) => a.instanceRefId,
165
+ object: (a) => a.instanceRefId,
166
+ enumeration: (a) => a.instanceRefId,
167
+ );
168
+ }
159
169
}
160
170
161
171
/// The path to visit child elements of an [Instance] or providers from `provider` /`riverpod` .
162
172
@freezed
163
- abstract class InstancePath with _$InstancePath {
173
+ class InstancePath with _$InstancePath {
164
174
const InstancePath ._();
165
175
166
176
const factory InstancePath .fromInstanceId (
167
- @nullable String instanceId, {
177
+ String instanceId, {
168
178
@Default ([]) List <PathToProperty > pathToProperty,
169
179
}) = _InstancePathFromInstanceId ;
170
180
@@ -175,7 +185,7 @@ abstract class InstancePath with _$InstancePath {
175
185
176
186
InstancePath get root => copyWith (pathToProperty: []);
177
187
178
- InstancePath get parent {
188
+ InstancePath ? get parent {
179
189
if (pathToProperty.isEmpty) return null ;
180
190
181
191
return copyWith (
0 commit comments