Search packages, repositories and app categories

Package detailsv0.2.0

kotlin_flavor

An utility package for providing static extension methods familiar in Kotlin.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
1.6K
Likes
26
Pub points
130

Install package

flutter pub add kotlin_flavor

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

kotlin_flavor is a Dart utility package that brings familiar Kotlin-style extension methods to Dart, enhancing code readability and expressiveness. It provides static extension methods for common operations like null safety, collection manipulation, and string utilities, mirroring Kotlin's concise syntax. Designed for developers transitioning from Kotlin or seeking more idiomatic Dart patterns, it simplifies everyday tasks without requiring runtime overhead. The package integrates seamlessly with Flutter and supports all major platforms.

Use cases

  • Enhancing Dart code with Kotlin-like syntax
  • Simplifying null checks and safe calls
  • Improving collection and string manipulation
  • Writing more readable and concise Dart code
  • Facilitating smoother migration from Kotlin

Key features

  • Kotlin-inspired extension methods
  • Static utility functions
  • Null safety helpers
  • Collection and string extensions
  • Cross-platform compatibility

Suitable for

  • Dart developers familiar with Kotlin
  • Teams seeking expressive Dart syntax
  • Projects aiming for cleaner code structure
  • Developers using Flutter on multiple platforms
  • Those wanting to reduce boilerplate

Considerations

  • Adds minimal runtime overhead
  • Not a full Kotlin port
  • Requires understanding of Kotlin idioms
  • May increase learning curve for new Dart devs
  • Best used in projects where code clarity is prioritized

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Dart CI Pub

kotlin_flavor

Are you Android-app engineer, and eager to use scope functions also in Dart?

Yes, kotlin_flavor/scope_functions provides it for you! :)

import 'package:kotlin_flavor/scope_functions.dart'

bool handle(Shop selectedShop) {
  return selectedShop?.let((shop) {
    navigateTo(shop.location);
    return true;
  }) ?? run(() {
    navigateToDefaultPosition();
    return false;
  });
}

kotlin_flavor/scope_functions

let

Often used for executing a code block only with non-null values.

someNullable?.let((it) { ... });
also

Used for additional actions that don't alter the object, such as logging or printing debug information.

something.also((it) { ... }); // returns something.
run

Used for evaluating a block of several statements where an expression is required.

someNullable ?? run(() {
  var defaultValue = ......;
  // several process...

  return defaultValue;
});

Development

$ docker-compose pull
$ docker-compose run --rm dart

will build a Dart development environment for you.

Ensure all test successfully pass, every after you change some codes:

$ pub run test

Categories

Source repository

Projects using this package

No data available yet.