ctx 0.0.3 copy "ctx: ^0.0.3" to clipboard
ctx: ^0.0.3 copied to clipboard

Immutable context for carrying data through an application.

example/ctx_example.dart

import 'package:ctx/ctx.dart';

void main() async {
  // Carrying values
  final ctx = const Context.empty()
      .withValue('user', 'alice')
      .withValue('role', 'admin');

  print('User: ${ctx['user']}'); // alice

  // Derive a new context without mutating the original:
  final scoped = ctx.withValue('role', 'editor');
  print('Original role: ${ctx['role']}'); // admin
  print('Scoped role: ${scoped['role']}'); // editor

  // Cancellation
  final (cancelCtx, cancel) = ctx.withCancel();

  cancel();
  await cancelCtx.done;

  print('Canceled? ${cancelCtx.error != null}'); // true
}
0
likes
160
points
373
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Immutable context for carrying data through an application.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on ctx