Line data Source code
1 : /// A compile-time–typed wrapper around a task ID string.
2 : ///
3 : /// Using `TaskId` instead of raw `String` makes accidental parameter swaps
4 : /// (e.g. `taskId` vs `tag`) a compile error rather than a silent runtime bug.
5 : ///
6 : /// ```dart
7 : /// const id = TaskId('daily-sync');
8 : ///
9 : /// await NativeWorkManager.cancel(taskId: id.value);
10 : /// // or — because TaskId implements String, it works wherever String is accepted:
11 : /// await NativeWorkManager.cancel(taskId: id);
12 : /// ```
13 : ///
14 : /// `TaskId` is a Dart 3 *extension type* — it has zero runtime overhead and
15 : /// erases to `String` at compile time.
16 : extension type const TaskId(String value) implements String {
17 : /// Returns true if the raw value is non-empty.
18 0 : bool get isValid => value.isNotEmpty;
19 : }
|