Skip to content
pubscout

plain_optional

1.0.0, released 5 years ago by an unverified publisher

An implementation of an Optional type in Dart, similar to Swift.

WASM-ready
$ flutter pub add plain_optional
Source repository

What it does

The plain_optional package defines a type Optional<T> that contains an object of type T optionally. It provides methods like map and flatMap to safely handle nullable values.

AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want a Swift-style Optional<T> type in Dart
  • You need to distinguish between uninitialized or absent values versus explicit nulls

Skip it when

  • Dart's built-in nullable types and null-safety operators are sufficient for your use case

Strengths

  • Provides familiar map and flatMap functions for handling optionals
  • Lightweight with no external dependencies

Weaknesses

  • Requires using a custom wrapper class instead of native Dart types

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
Optional<String> optionalValue = Optional.of('Hello');
String? unwrapped = optionalValue.unsafe;

Alternatives

Packages that do the same job and could replace plain_optional.

  • result_dart

    Kotlin and Swift inspired Result class for error handling in Dart and Flutter.

  • result_type

    A Result type representing success or failure in Dart

  • minted

    Shared vocabulary types and outcomes for the minted family of domain-parsing packages.

  • optional

    An implementation of the Optional type to help avoid null reference errors.

Works with

Packages commonly used together with plain_optional: ones it builds on, ones built on it, and its own family.