-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
multiple_constructors.dart
159 lines (135 loc) · 4.5 KB
/
multiple_constructors.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import 'package:freezed_annotation/freezed_annotation.dart';
part 'multiple_constructors.freezed.dart';
@unfreezed
class UnfreezedImmutableUnion with _$UnfreezedImmutableUnion {
factory UnfreezedImmutableUnion(final String a) =
DirectUnfreezedImmutableUnion;
factory UnfreezedImmutableUnion.named(String a) =
DirectUnfreezedImmutableUnionNamed;
}
@unfreezed
class UnfreezedImmutableUnion2 with _$UnfreezedImmutableUnion2 {
factory UnfreezedImmutableUnion2(String a) = DirectUnfreezedImmutableUnion2;
factory UnfreezedImmutableUnion2.named(final String a) =
DirectUnfreezedImmutableUnionNamed2;
}
@unfreezed
class MutableUnion with _$MutableUnion {
factory MutableUnion(String a, int b) = MutableUnion0;
factory MutableUnion.named(String a, int c) = MutableUnion1;
}
@freezed
class DefaultValueNamedConstructor with _$DefaultValueNamedConstructor {
factory DefaultValueNamedConstructor.a([@Default(42) int value]) =
_ADefaultValueNamedConstructor;
factory DefaultValueNamedConstructor.b([@Default(42) int value]) =
_BDefaultValueNamedConstructor;
}
@freezed
class NamedDefaultValueNamedConstructor
with _$NamedDefaultValueNamedConstructor {
factory NamedDefaultValueNamedConstructor.a({@Default(42) int value}) =
_BNamedDefaultValueNamedConstructor;
factory NamedDefaultValueNamedConstructor.b({@Default(42) int value}) =
_ANamedDefaultValueNamedConstructor;
}
@freezed
class NoCommonParam with _$NoCommonParam {
const factory NoCommonParam(String a, {int? b}) = NoCommonParam0;
const factory NoCommonParam.named(double c, [Object? d]) = NoCommonParam1;
}
// Regression test for https://github.com/rrousselGit/freezed/issues/358
@freezed
class Regression358 with _$Regression358 {
const factory Regression358({
required int number,
}) = _Regression358;
factory Regression358.withSpecificColor({int count = 2}) =>
Regression358(number: count);
}
@freezed
class SharedParam with _$SharedParam {
const factory SharedParam(String a, int b) = SharedParam0;
const factory SharedParam.named(String a, int c) = SharedParam1;
}
@freezed
class SharedParamNullable with _$SharedParamNullable {
const factory SharedParamNullable(String a, String b, int c) =
SharedParamNullable0;
const factory SharedParamNullable.named(String? a, String b, int d) =
SharedParamNullable1;
}
@freezed
class Complex with _$Complex {
@Assert("a != ''", '"Hello"')
const factory Complex(
/// Hello
String a,
) = Complex0;
@Assert("a == ''")
@Assert('b == true', 'b must be true')
const factory Complex.first(
/// World
String a, {
/// B
bool? b,
double? d,
}) = Complex1;
const factory Complex.second(
String a, [
/// C
int? c,
double? d,
]) = Complex2;
}
@freezed
class SwitchTest with _$SwitchTest {
const factory SwitchTest(String a) = SwitchTest0;
const factory SwitchTest.first(String a, {bool? b, double? d}) = SwitchTest1;
const factory SwitchTest.second(String a, [int? c, double? d]) = SwitchTest2;
}
@freezed
class NoDefault with _$NoDefault {
const factory NoDefault.first(String a) = NoDefault1;
const factory NoDefault.second(String a) = NoDefault2;
}
@freezed
class NameConflict with _$NameConflict {
factory NameConflict.something(Error error) = Something;
factory NameConflict.error(Error error) = SomeError;
}
@freezed
class Recursive with _$Recursive {
factory Recursive() = RecursiveImpl;
factory Recursive.next(RecursiveImpl value) = _RecursiveNext;
}
@freezed
class RequiredParams with _$RequiredParams {
const factory RequiredParams({required String a}) = RequiredParams0;
const factory RequiredParams.second({required String a}) = RequiredParams1;
}
@freezed
class NestedList with _$NestedList {
factory NestedList.shallow(List<LeafNestedListItem> children) =
ShallowNestedList;
factory NestedList.deep(List<InnerNestedListItem> children) = DeepNestedList;
}
@freezed
class NestedListItem with _$NestedListItem {
factory NestedListItem.leaf() = LeafNestedListItem;
factory NestedListItem.inner(List<LeafNestedListItem> children) =
InnerNestedListItem;
}
@freezed
class NestedMap with _$NestedMap {
factory NestedMap.shallow(Map<String, LeafNestedMapItem> children) =
ShallowNestedMap;
factory NestedMap.deep(Map<String, InnerNestedMapItem> children) =
DeepNestedMap;
}
@freezed
class NestedMapItem with _$NestedMapItem {
factory NestedMapItem.leaf() = LeafNestedMapItem;
factory NestedMapItem.inner(Map<String, LeafNestedMapItem> children) =
InnerNestedMapItem;
}