either_type 0.1.2

  • Readme
  • Changelog
  • Installing
  • 68

Either #

The library for Error Handling.

main() async {
  // There is some method that will return the user or error.
  await getUser()
    ..either((ServerError error) {
      // Add a handler for the error.
      print("Error: ${error.code}");
    }, (User user) {
      // Add a handler to get the user.
      print("User: ${user.name}");

  // or
  final either = await getUser();
  if (either.isLeft) {
    final error = either.left;
    print("Error: ${error.code}");
  } else {
    final user = either.right;
    print("User: ${user.name}");

// And the return of either looks like this.
// According to the agreement, the right part stores the result of success,
// left is wrong.
Future<Either<ServerError, User>> getUser() async =>
    (Random().nextBool()) ? Right(User("Bob")) : Left(ServerError(500));

Installation #

Add on pubspec.yml:

  either_type: ^0.1.2

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.1.0] - The base implementation either type.

[0.1.2] - Added getters of left/right values.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  either_type: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:either_type/either_type.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:either_type/either_type.dart.

Health suggestions

Fix lib/src/either.dart. (-2.48 points)

Analysis of lib/src/either.dart reported 5 hints:

line 12 col 7: DO use curly braces for all flow control structures.

line 23 col 7: DO use curly braces for all flow control structures.

line 25 col 7: DO use curly braces for all flow control structures.

line 30 col 7: DO use curly braces for all flow control structures.

line 32 col 7: DO use curly braces for all flow control structures.

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and either_type.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0