blackbird 0.0.1 copy "blackbird: ^0.0.1" to clipboard
blackbird: ^0.0.1 copied to clipboard

A boolean logic library for Dart and Flutter, allowing you to build trees of conditions and evaluate them.

example/blackbird_example.dart

import 'package:blackbird/blackbird.dart';

sealed class StringTest extends Test<String> {}

class ContainsString extends StringTest {
  ContainsString(this.value);
  final String value;

  @override
  bool call(String t) {
    return t.contains(value);
  }

  @override
  List<Object?> get props => [value];
}

class StartsWithLowerCase extends StringTest {
  StartsWithLowerCase();

  @override
  bool call(String t) {
    if (t.isEmpty) return false;
    final test = t.substring(0, 1);
    final regex = RegExp(r'^[a-z]$');
    return regex.hasMatch(test);
  }

  @override
  List<Object?> get props => [];
}

void main() {
  final condition = And(
    [
      IsTrue(StartsWithLowerCase()),
      IsTrue(ContainsString('One')),
    ],
  );

  print(condition.evaluate('payeeOne')); // true
  print(condition.evaluate('PayeeOne')); // false
}
0
likes
0
points
51
downloads

Publisher

unverified uploader

Weekly Downloads

A boolean logic library for Dart and Flutter, allowing you to build trees of conditions and evaluate them.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, equatable, uuid

More

Packages that depend on blackbird