zone_local 0.1.0 copy "zone_local: ^0.1.0" to clipboard
zone_local: ^0.1.0 copied to clipboard

discontinued
outdated

Zone-scoped values. Can be used an alternative to dependency injection.

example/zone_local.dart

import 'package:zone_local/zone_local.dart';

void main() {
  // Configure a zone-local service.
  // The method also prevents later (accidental) modification of the default value.
  GreetingService.zoneLocal
      .freezeDefaultValue(GreetingService("Hello, world!"));

  // Use the service
  print(GreetingService.zoneLocal.value.greeting);
  // --> Hello, world!

  // Fork a zone with different value
  final forkedZone = GreetingService.zoneLocal
      .forkZoneWithValue(GreetingService("Hi, forked zone!"));
  forkedZone.run(() {
    print(GreetingService.zoneLocal.value.greeting);
    // --> Hi forked, zone!
  });
}

class GreetingService {
  static final ZoneLocal<GreetingService> zoneLocal =
      ZoneLocal<GreetingService>();

  final String greeting;
  GreetingService(this.greeting);
}
0
likes
0
pub points
7%
popularity

Publisher

unverified uploader

Zone-scoped values. Can be used an alternative to dependency injection.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on zone_local