behaviour 3.0.1 copy "behaviour: ^3.0.1" to clipboard
behaviour: ^3.0.1 copied to clipboard

This package adds support for behaviours. Behaviours are classes of which the instances are used as functions.

example/behaviour_example.dart

import 'dart:async';
import 'dart:developer';

import 'package:behaviour/behaviour.dart';

class CreateCustomer extends Behaviour<CreateCustomerParams, void> {
  @override
  Future<void> action(CreateCustomerParams input, BehaviourTrack? track) {
    log('TODO create customer: ${input.name} - ${input.phoneNumber}');
    return Future.value();
  }

  @override
  FutureOr<Exception> onCatchError(
    Object e,
    StackTrace stackTrace,
    BehaviourTrack? track,
  ) {
    return Exception('An unknown error occurred: $e');
  }
}

class CreateCustomerParams {
  const CreateCustomerParams({
    required this.name,
    required this.phoneNumber,
  });

  final String name;
  final String phoneNumber;
}

Future<void> main() async {
  final createCustomer = CreateCustomer();
  await createCustomer(
    const CreateCustomerParams(
      name: 'Wim',
      phoneNumber: '+32 xxx xx xx xx',
    ),
  );
}
1
likes
160
points
61
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

This package adds support for behaviours. Behaviours are classes of which the instances are used as functions.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

async

More

Packages that depend on behaviour