optional 2.0.1+2

  • README.md
  • Installing
  • Versions
  • 81


Optional.dart is an implementation of the Optional type, inspired by Java 8's Optional class.



  • Compatibility with Dart 2


  • Add an optional orElse parameter to ifPresent.


  • Optional.empty() constructor is now const.


  • Absent and Present are now subclasses of Optional. You should continue to use constructors in Optional, and not the Absent or Present ones.
  • EMPTY is now a top-level constant.


  • Operators are now overloaded, so you can add, subtract, etc., Optionals. Any operation involving an empty Optional will return an empty Optional.
  • Added examples.


  • Optional.ofNullable() and Optional.empty() constructors are now const.
  • Optional.of() constructor now throws ArgumentError when passed null, instead of NoValuePresentError.
  • NoValuePresentError now extends StateError.


  • Initial release

Use this package as a library

1. Depend on it

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

  optional: "^2.0.1+2"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

      import 'package:optional/optional.dart';
Version Uploaded Documentation Archive
2.0.1+2 Jun 6, 2018 Go to the documentation of optional 2.0.1+2 Download optional 2.0.1+2 archive
2.0.1+1 Jun 6, 2018 Go to the documentation of optional 2.0.1+1 Download optional 2.0.1+1 archive
2.0.1 Jun 6, 2018 Go to the documentation of optional 2.0.1 Download optional 2.0.1 archive
2.0.0 Jun 6, 2018 Go to the documentation of optional 2.0.0 Download optional 2.0.0 archive
1.2.3+1 Dec 15, 2015 Go to the documentation of optional 1.2.3+1 Download optional 1.2.3+1 archive
1.2.3 Dec 15, 2015 Go to the documentation of optional 1.2.3 Download optional 1.2.3 archive
1.2.2 Oct 2, 2014 Go to the documentation of optional 1.2.2 Download optional 1.2.2 archive
1.2.1+4 Sep 14, 2014 Go to the documentation of optional 1.2.1+4 Download optional 1.2.1+4 archive
1.2.1+3 Sep 12, 2014 Go to the documentation of optional 1.2.1+3 Download optional 1.2.1+3 archive
1.2.1+2 Sep 12, 2014 Go to the documentation of optional 1.2.1+2 Download optional 1.2.1+2 archive

All 15 versions...


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
63 / 100
Code health derived from static analysis. [more]
97 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

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


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 5 hints.

    Run dartfmt to format lib/optional.dart.

    Run dartfmt to format lib/optional_internal.dart.

    Similar analysis of the following files failed:

    • lib/src/absent.dart (hint)
    • lib/src/novaluepresent.dart (hint)
    • lib/src/present.dart (hint)
  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use optional.dart.


Package Constraint Resolved Available
Dev dependencies
mockito ^2.0.0
test ^0.12.0