dartlin 0.3.0

Flutter Android iOS web

Dartlin is a helper library that provides readable methods with which you can write cleaner looking code.

dartlin #

coverage report pipeline status
plugin version dependencies

Introduction #

What it does #

Dartlin is a helper library that provides readable methods with which you can write cleaner looking code.

  • It allows you to have more control over your code flow. By using the when method for example, to write switch-like expressions.
  • It provides methods to create data sets of certain types, for example the range method.

What it does not do #

Dartlin is by definition not a performance optimization library, the main focus is adding readable methods that help you keep your code clean. And readability does not always equal performance optimization. So if you are looking to optimize your code, this is not the library for you.

Note: The performance hit of the provided methods tends to be very minimal, but most of them do rely on closures to work.

Common Usage #

Control flow #

The Dartlin control_flow library provides methods for writing cleaner and more controllable code, these control flow methods can be used as a replacement for existing control flow statements or in combination with them.

Note: Dart already provides a few interesting control flow operations for Lists and Maps. So before you decide to use Dartlin, first read more about collection operators. It may already suit your needs.

if-statement as expressions

The iff method works like the if statement, but with the added bonus of being able to write them as expressions. You can use them to replace complex ternary operators with a readable if-like statement:

final x = iff(a < b, () {
  return a;
}).elseIf(a == b, () {
  return 0;
}).orElse(() {
  return b;
});

See the iff docs for more information.

switch-like statements as expressions

The when method replaces the switch statement. And can be used to write expressions:

final result = when(place, {
  1: () => CompetitionPlace.first,
  2: () => CompetitionPlace.second,
  3: () => CompetitionPlace.third,
  [4,5]: () => CompetitionPlace.honourableMentions,
  orElse: () => CompetitionPlace.others
});

See the when docs for more information.

Development and Contributing #

Interested in contributing? We love merge requests! See the Contribution guidelines.

Collections #

Creating progression ranges

The range method allows the user to easily create a lists of certain num types. While being able to define the start value, the end value, the steps it should take to reach the end value and if it should be created in reverse or not:

// [0, 1, 2, 3, 4]
final list1 = range(0, to: 4);

// [4, 3, 2, 1, 0]
final list2 = range(4, downTo: 0); 

// [1, 3, 5, 7]
final list3 = range(1, to: 8, step: 2);

// [1, 2, 3]
final list4 = range(0, until: 4);

See the range docs for more information.

3
likes
100
pub points
6%
popularity

Publisher

wolfenra.in

Dartlin is a helper library that provides readable methods with which you can write cleaner looking code.

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on dartlin