@@ -7,7 +7,7 @@ description: Learn about the experimental macros feature as it develops.
7
7
*** currently under development*** which adds support for
8
8
[ static meta-programming] [ motivation ] to the Dart language.
9
9
10
- A Dart macro is a user-defineable piece of code that takes in other code as parameters
10
+ A Dart macro is a user-definable piece of code that takes in other code as parameters
11
11
and operates on it in real-time to create, modify, or add declarations.
12
12
13
13
You can think about the macro system in two parts: using macros and writing macros.
@@ -56,10 +56,11 @@ and a `fromJson` deserialization constructor.
56
56
57
57
2 . Run ` dart --version ` and make sure you have Dart version ` 3.5.0-152 ` or later.
58
58
59
- 3 . [ Add the package] [ ] to your pubspec and retrieve
60
- its dependencies.
59
+ 3 . Edit the [ SDK constraint] [ ] in your pubspec to require that Dart version: ` sdk: ^3.5.0-152 `
61
60
62
- 4 . [ Add the experiment] [ ] to the ` analysis_options.yaml `
61
+ 4 . [ Add the package] [ ] ` json ` to ` dependencies ` in your pubspec and run ` pub get ` .
62
+
63
+ 5 . [ Add the experiment] [ ] to the ` analysis_options.yaml `
63
64
file at the root of your project:
64
65
65
66
``` yaml
@@ -68,18 +69,19 @@ and a `fromJson` deserialization constructor.
68
69
- macros
69
70
` ` `
70
71
71
- 5 . Import the package in the file you plan to use it:
72
+ 6 . Import the package in the file you plan to use it:
72
73
73
74
` ` ` dart
74
75
import 'package:json/json.dart';
75
76
```
76
77
77
- 6 . Run your project with the experiment flag:
78
+ 7 . Run your project with the experiment flag:
78
79
79
80
``` console
80
81
dart run --enable-experiment=macros bin/my_app.dart
81
82
```
82
83
84
+ [ SDK constraint ] : /tools/pub/pubspec#sdk-constraints
83
85
[ Add the package ] : /guides/packages
84
86
[ Add the experiment ] : /tools/experiment-flags#using-experiment-flags-with-the-dart-analyzer-command-line-and-ide
85
87
@@ -136,7 +138,7 @@ adjust in real time alongside your application code:
136
138
137
139
### Trigger custom diagnostics
138
140
139
- The ` JsonCodable ` macro has built-in diagnostics that are emmitted just like
141
+ The ` JsonCodable ` macro has built-in diagnostics that are emitted just like
140
142
diagnostics from the language itself. For example, if you try to manually
141
143
declare a ` toJson ` method where the macro is applied, the analyzer will emit
142
144
the error:
0 commit comments