behaviour 2.1.1 copy "behaviour: ^2.1.1" to clipboard
behaviour: ^2.1.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 'package:behaviour/behaviour.dart';

class CreateCustomer extends Behaviour<CreateCustomerParams, void> {
  @override
  Future<void> action(CreateCustomerParams input, BehaviourTrack? track) {
    // TODO logic to create a customer
    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.address,
    required this.phoneNumber,
  });

  final String name;
  final String address;
  final String phoneNumber;
}

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

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

Documentation

API reference

License

MIT (license)

Dependencies

async

More

Packages that depend on behaviour