scope
  • Overview
  • Fundamentals
    • Installing
    • Scope
      • Creating
      • Using
      • Detecting
      • Nesting
      • Async
      • Single and Sequence factories
      • Returning values
      • Mutable values
    • GlobalScope
    • Overriding
    • Type safety
    • Debugging
    • How Scope Works
  • Guides
    • Best Practice
    • How is Scope different from 'x'
Powered by GitBook
On this page
  1. Fundamentals
  2. Scope

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.
}

PreviousSingle and Sequence factoriesNextMutable values

Last updated 3 years ago