@@ -12,7 +12,7 @@ Generate sealed class hierarchy for Dart and Flutter, For null-safe and legacy p
1212
1313## Features
1414
15- * Generate sealed class with abstract super type and data sub classes.
15+ * Generate sealed class with abstract super type and data sub- classes.
1616* Static factory methods. for example ` Result.success(data: 0) ` .
1717* Cast methods. for example ` a.asSuccess() ` , ` a.isSuccess() ` or ` a.asSuccessOrNull() ` .
1818* Three types of equality and hashCode generation : data (like kotlin data classes), identity and distinct.
@@ -53,7 +53,7 @@ part 'weather.sealed.dart';
5353Add `@Sealed` annotation, and an abstract private class as a manifest for generated code.
5454
5555You can choose between three types of equality using `@WithEquality(...)` annotation. Default equality is `data` if not
56- specified. This will become default equality for all sub classes. You can change equality of each sub class by using
56+ specified. This will become default equality for all sub- classes. You can change equality of each sub- class by using
5757this annotation on individual methods.
5858
5959Equality types :
@@ -92,14 +92,14 @@ abstract class _Weather {
9292` ` `
9393
9494An abstract super class is generated with name equal to name of manifest class without the underline (here `Weather`).
95- Each method will become a sub class. There should be at least one method. Sub class names are based on method name
95+ Each method will become a sub- class. There should be at least one method. sub- class names are based on method name
9696prefixed with super class name (for example `WeatherSunny`). Naming process can be tailored with use of `@WithPrefix`
97- and `@WithName` annotations. Each method argument will become a field in corresponding sub class. Field names are equal
97+ and `@WithName` annotations. Each method argument will become a field in corresponding sub- class. Field names are equal
9898to argument names and field types are equal to argument types or dynamic if not specified. Argument types can be
9999overridden using `@WithType` annotation for example when type information is not available at build time. Note that you
100100can have nullable and non-nullable fields. In legacy projects all fields are considered nullable.
101101
102- To change prefix of sub class names which by default is top class name, you can use `@WithPrefix` annotation. for
102+ To change prefix of sub- class names which by default is top class name, you can use `@WithPrefix` annotation. for
103103example :
104104
105105` ` ` dart
@@ -111,9 +111,9 @@ abstract class _Weather {
111111` ` `
112112
113113Now `sunny` will be named `HelloSunny` instead of the default `WeatherSunny`. You can use `@WithPrefix('')` to remove
114- all prefix from sub class names.
114+ all prefix from sub- class names.
115115
116- To change sub class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
116+ To change sub- class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
117117example :
118118
119119` ` ` dart
@@ -124,11 +124,11 @@ abstract class _Weather {
124124}
125125` ` `
126126
127- Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is use full if you want not to use prefix
127+ Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is useful if you want not to use prefix
128128for some items.
129129
130- Almost all methods on sealed classes use short names extracted from manifest method names. Full sub class names are not
131- used. It is recommended not to use sub classes directly. There are factory methods for each item on super class.
130+ Almost all methods on sealed classes use short names extracted from manifest method names. Full sub- class names are not
131+ used. It is recommended not to use sub- classes directly. There are factory methods for each item on super class.
132132
133133Then run the following command to generate code for you.
134134
@@ -140,8 +140,7 @@ The generated code will look like: (the following code is summarised)
140140
141141` ` ` dart
142142abstract class Weather {
143- static WeatherRainy rainy({required int rain}) =>
144- WeatherRainy(rain: rain);
143+ factory Weather.rainy({required int rain}) = WeatherRainy;
145144
146145 bool isRainy() => this is WeatherRainy;
147146
@@ -213,9 +212,6 @@ class WeatherRainy extends Weather with EquatableMixin {
213212
214213 final int rain;
215214
216- WeatherRainy copy({int? rain}) =>
217- WeatherRainy(rain: rain ?? this.rain);
218-
219215 @override
220216 String toString() => 'Weather.rainy(rain: $rain)';
221217
@@ -231,7 +227,7 @@ class WeatherWindy extends Weather {
231227Notes :
232228
233229- Always use exact match method that you need, for example do not use `whenOrNull` instead of `whenPartial`.
234- - Prefer using factories in super class instead of sub class constructors.
230+ - Prefer using factories in super class instead of sub- class constructors.
235231- Minimize usage of cast methods, most of the time they can be replaced with a match method.
236232
237233# # Generic Usage
@@ -276,7 +272,7 @@ abstract class _Result<D extends num, E extends Object> {
276272# # Wrapping and Inheritance
277273
278274There are times when you are using a sealed type only to wrap some fields and then unwrap it by using match functions in
279- for example your blocs. In these situations it is better for the sealed sub class not to appear explicitly.
275+ for example your blocs. In these situations it is better for the sealed sub- class not to appear explicitly.
280276
281277for example suppose the following manifest :
282278
@@ -332,8 +328,8 @@ Object doTest(State s) {
332328}
333329` ` `
334330
335- As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub classes.
336- If you want wrapping only for some of your sub classes apply them to methods. for example :
331+ As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub- classes.
332+ If you want wrapping only for some of your sub- classes apply them to methods. for example :
337333
338334` ` ` dart
339335@Sealed()
@@ -350,7 +346,7 @@ abstract class State {
350346
351347In previous example `data` will not be automatically unwrapped.
352348
353- Also, when making a sealed sub class wrapped, its constructor and the corresponding factory in sealed super class will
349+ Also, when making a sealed sub- class wrapped, its constructor and the corresponding factory in sealed super class will
354350be using positional arguments instead of named arguments. For example for `data` :
355351
356352` ` ` dart
@@ -408,7 +404,7 @@ For more information check `super_enum` documentation:
408404
409405# ## migrating from super_enum
410406
411- If you were using super_enum and now you want to change your dependency to dart_sealed :
407+ If you were using super_enum, and now you want to change your dependency to dart_sealed :
412408
413409* Change dependency of `super_enum` with `super_enum_sealed_annotations`.
414410* Add dependency to `sealed_annotations`.
0 commit comments