Skip to content
pubscout

scope

5.1.0, released 2 years ago by onepub.dev

A Dart library for dependency injection using scopes and call‑stack based values.

WASM-ready
$ flutter pub add scope
Source repository

What it does

Scope lets you inject values into a runtime scope and retrieve them anywhere within that call stack. It supports nested scopes, singletons, sequences and async execution.

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

Use it when

  • You need call‑stack based DI without widget‑tree coupling
  • You want nested scopes or temporary overrides for testing
  • You prefer a lightweight, code‑generation‑free solution

Skip it when

  • You rely heavily on Flutter's BuildContext for DI
  • You need compile‑time code‑gen for type‑safe factories
  • You require platform‑specific integrations like permissions

Strengths

  • Simple, zero‑boilerplate API
  • Supports nested scopes and temporary overrides
  • Works with pure Dart, no Flutter dependency

Weaknesses

  • No code‑gen or compile‑time safety
  • Not integrated with Flutter widget tree like Provider
  • Async run change may break existing code

Setup

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

final ageKey = ScopeKey<int>();

void main() async {
  await Scope()
    ..value<int>(ageKey, 30)
    ..run(() => print('Age: ${use(ageKey)}'));
}

Alternatives

Packages that do the same job and could replace scope.

Works with

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