t×tecexpressby TeKOcloud
DEv0.7.1
API & types / FLUTTER

TxCancellation.

Cooperative cancellation with one-shot listeners; throwIfCancelled throws StateError after cancellation.

Member / type / returnMeaning
bool isCancelled = falseWhether cancellation has been requested.
void cancel()Set synchronously to true to cancel the action.
VoidCallback onCancel(VoidCallback listener)Registers a cancellation listener; called immediately if already cancelled. The return value unregisters it.
void throwIfCancelled()Throws StateError if the token was cancelled.
dart
import 'package:flutter/material.dart';
import 'package:tecexpress/tecexpress.dart';

Future<void> example() async {
  final token = TxCancellation();
  final unregister = token.onCancel(() => debugPrint('Cancelled'));
  token.throwIfCancelled();
  token.cancel();
  unregister();
}