Quick Start
This page walks through the minimum you need to wire an app with CherryPick. It assumes
you have already installed the cherrypick package.
1. Describe a module
Section titled “1. Describe a module”A module groups the bindings that
tell CherryPick how to build each dependency. Override builder and call bind<T>()
for every type you want to provide:
import 'package:cherrypick/cherrypick.dart';
class AppModule extends Module { @override void builder(Scope currentScope) { // A ready-made instance. bind<ApiClient>().toInstance(ApiClientMock());
// A factory, called on every resolve. bind<String>().toProvide(() => "Hello, CherryPick!"); }}2. Open a scope and install the module
Section titled “2. Open a scope and install the module”The root scope is the top of the dependency tree. Install your modules into it once, at startup:
final rootScope = CherryPick.openRootScope();rootScope.installModules([AppModule()]);3. Resolve dependencies
Section titled “3. Resolve dependencies”Ask the scope for a type. Use resolveAsync for async bindings and tryResolve when a
missing binding is a normal case rather than an error — see the
Dependency Resolution API.
final greeting = rootScope.resolve<String>();print(greeting); // prints: Hello, CherryPick!4. Close the scope
Section titled “4. Close the scope”When the app (or test) is done, close the scope. This disposes every
Disposable the scope owns. Always await it — even if
nothing is disposable today:
await CherryPick.closeRootScope();Using it in Flutter
Section titled “Using it in Flutter”Add cherrypick_flutter and wrap your app in CherryPickProvider. Widgets below it can
reach the scopes through CherryPickProvider.of(context):
import 'package:cherrypick/cherrypick.dart';import 'package:cherrypick_flutter/cherrypick_flutter.dart';import 'package:flutter/material.dart';
void main() { CherryPick.openRootScope().installModules([AppModule()]); runApp(const CherryPickProvider(child: MyApp()));}
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { final scope = CherryPickProvider.of(context).openRootScope(); return MaterialApp(home: Text(scope.resolve<String>())); }}CherryPickProvider.of(context).openSubScope(scopeName: 'feature') opens a
subscope for a feature or a screen.
Next steps
Section titled “Next steps”- Using Annotations — generate modules and field injection instead of writing them by hand.
- Hierarchical Subscopes — isolate features and screens.
- Example Application — a complete app wired with CherryPick.
- Linting — catch common mistakes in the IDE.