v0.1.2
data_class
使用 pkg:macros 在 Dart 中實驗性支援資料類別
60喜歡 51近 30 天下載50Pub 分數
平台暫無資料
使用宏在 Dart 中實驗性地支援資料類別。
以下為英文專案原文快照,最新內容請造訪 GitHub。
Support for data classes in Dart using macros.
🪨 const constructors with required, named parameters
🖨️ copyWith with optional, nullable, named parameters
✨ toString for an improved string representation
☯️ operator== and hashCode for value equality
import 'package:data_class/data_class.dart';
@Data()
class Person {
final String name;
}
void main() {
// 🪨 Create a const instance with required, name parameters.
const dash = Person(name: 'Dash');
// 🖨️ Create copies of your object.
final sparky = dash.copyWith(name: 'Sparky');
// ✨ Human-readable string representation.
print(dash); // Person(name: Dash)
print(sparky); // Person(name: Sparky)
// ☯️ Value equality comparisons.
print(dash == dash.copyWith()); // true
print(dash == sparky); // false
}
Add package:data_class to your pubspec.yaml
dependencies:
data_class: any
Enable experimental macros in analysis_options.yaml
analyzer:
enable-experiment:
- macros
Use the @Data annotation (see above example).
Run it
dart --enable-experiment=macros run main.dart
*Requires Dart SDK >= 3.5.0
依賴清單 4 項
^1.0.0^3.0.0-dev^0.1.0-main.5^1.0.0先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗