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

Missing Kotlin methods ? let / run / also / takeIf / when / if ? try this awesome repository

missing_kotlin #

"Flutter is **** because it does not use Kotlin" Already heard it ? Prove them you can do the same thing as Kotlin using Flutter/Dart !

.let #

Work like .let in kotlin

final calculated = myMethod()?.let((v){
  return v*2;
}) ?? 0;

Will also break th chain if th expression is null

String variable; //null
final calculated = variable?.let((v) => v.length());

//here the expression is null, it will not execute the lambda
expect(calculated, null);

.also #

Work like .also in kotlin

final result = myMethod()?.also((v){
  print(v);
});

result here is the return value of myMethod()

.run #

Work like .run in kotlin

final calculated = myMethod()?.let((v){
  return v*2;
}) ?? run(() => 3);

.takeIf #

Work like .takeIf in kotlin

final calculated = myMethod()?.takeIf((v) => v == 3)?.let((v){
  return v*2;
}) ?? 0;

When #

final variable = 3;
final result = when(variable, [
    Case(2, () => "A"),
    Case(3, () => "B"),
    Default(() => "C"),
]);

//here the result is "B"
expect(calculated, null);

If #

Like a Kotlin if, returning a value, but with an Uppercase (because if is a reserved work)

final result = If(1 == 1, 
  () => "A", 
  Else: () => "B"
);

//here the result is "B"
expect(result, "B");

You can also chain statements

final result = If(variable2 == 2,
    () => "A",
  Else: () => 
    If(variable2 == 3,
        () => "B",
    Else: 
        () => "C"
  ),
);

//here the result is "C"
expect(result, "C");
1
likes
10
pub points
0%
popularity

Publisher

unverified uploader

Missing Kotlin methods ? let / run / also / takeIf / when / if ? try this awesome repository

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on missing_kotlin