Returning values

You can return a value from a Scope's run method.

import 'package:scope/scope.dart';

void main() {

  /// buld the scope
  final greeter = (Scope()
     ..value<String>(greetingToken, 'Hello')
     ..value<int>(emphasisToken,  1))
     /// run code in the scope getting the return value
     .run<Greeter>(Greeter());

  /// use the returned value  
  greeter.greet('world'); // `greeter` can now be used outside of the scope
                          // but will have no access to scope keys.
}

Last updated