Skip to content
pubscout

enum_flag

3.0.0, released 3 months ago by an unverified publisher

Portable enum bit flags for Dart with typed FlagSet values and stable bit positions.

WASM-ready
$ flutter pub add enum_flag
Source repository

What it does

Provides type-safe enum bit flags for Dart. Allows defining flags with unique explicit bit positions or index-based values, offering immutable FlagSet operations, integer extensions, and handling for unknown bits.

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

Use it when

  • You need to store multiple enum-based states efficiently inside a single integer bitmask.
  • You require stable bit positions for database storage or external API serialization.
  • You want immutable, typed flag set operations without code generation.

Skip it when

  • You are dealing with more than 32 flags (since positions are limited to 0-31 for standard 32-bit unsigned integers).

Strengths

  • Stable explicit bit positions for persisted data and APIs.
  • Immutable and typed FlagSet API alongside classic int extensions.
  • Preserves and reports unknown bits for forward compatibility.
  • Guaranteed identical unsigned 32-bit behavior across Dart VM and JavaScript.

Weaknesses

  • Limited to a maximum of 32 bits (positions 0 through 31).
  • Requires manual migration or explicit configuration if flag orders change.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:enum_flag/enum_flag.dart';

enum Permission with EnumFlag {
  read(0),
  write(1),
  execute(2),
  delete(3);

  const Permission(this.bitIndex);

  @override
  final int bitIndex;
}

final permissions = [Permission.read, Permission.execute].flagSet;

Alternatives

Packages that do the same job and could replace enum_flag.