Installation
Add magic_starter to a Magic app, register its dowel commands with plugin:install, and let starter:install scaffold the config, middleware, models and routes for the features you choose.
On this page
Requirements#
The Dart and Flutter floors are inherited from magic: a package cannot resolve below its own dependency's floor.
| Dependency | Constraint |
|---|---|
| Dart SDK | >=3.13.0 <4.0.0 |
| Flutter | >=3.47.0 |
magic |
^1.0.0 |
dowel |
^1.0.0 |
magic_notifications |
^1.0.0 |
magic_payments |
^1.0.0 |
magic_picker |
^1.0.0 |
magic_socket |
^1.0.0 |
args |
^2.7.0 |
path |
^1.9.1 |
in_app_review |
^2.0.12 |
package_info_plus |
^10.2.2 |
web |
^1.1.2 |
The starter imports no analytics package, so nothing here resolves Firebase for you. To use the analytics feature, install magic_analytics yourself (flutter pub add magic_analytics, then dart run magic:dowel plugin:install magic_analytics) or any analytics package, and connect it as described in Analytics Preference Callback.
The UI is built on wind_kit and material_ui, which come with magic. The app must already be scaffolded by Magic (lib/config/app.dart present): run dart run magic:dowel magic:install first, see the Magic installation guide.
The package is the client of magic-starter-laravel's api/v1 routes: its controllers call them one to one, so the screens need that backend, or one that serves the same routes, to work.
Installing the Package#
flutter pub add magic_starter
dart run magic:dowel plugin:install magic_starter --no-bootstrap
plugin:install registers MagicStarterDowelProvider under .dowel/plugins.json and injects MagicStarterServiceProvider into lib/config/app.dart. Without --no-bootstrap it also chains starter:install as the plugin's bootstrap command.
The package has no executable of its own: every command is dart run magic:dowel starter:<command>.
Running the Install Command#
dart run magic:dowel starter:install
Interactively, the command asks one yes/no question per feature key and defaults every answer to no. For a scripted install pass the keys you want:
dart run magic:dowel starter:install --features=registration,teams,notifications
--features implies --non-interactive; a key you leave out is written as false. The accepted keys are the ones in the feature toggles table.
The command then:
- Validates that
lib/config/app.dartexists and stops when it does not. - Writes
lib/config/magic_starter.dartwith your selections, theEnsureAuthenticatedandRedirectIfAuthenticatedmiddleware underlib/app/middleware/,lib/app/models/user.dart(andteam.dartwhenteamsis on),lib/resources/views/dashboard_view.dartandlib/routes/app.dart. A file that already exists is skipped, exceptlib/routes/app.dart, which gets the dashboard route group injected instead. - Injects
MagicStarterServiceProviderintolib/config/app.dart, the config import andmagicStarterConfigfactory intolib/main.dart(with a defaultprimarypalette passed aswindTheme), theauthandguestaliases intolib/app/kernel.dartand the route registrations intolib/app/providers/route_service_provider.dart. - Edits
lib/app/providers/app_service_provider.dart: it injects theMagicStarter.bootstrap(...)call and a navigation block into an existing file, or writes a full one when the file is missing or--forceis passed. - Merges the starter's translation keys into
assets/lang/en.jsonand registers that asset in the hostpubspec.yaml. - Adds
magic_notificationsto the hostpubspec.yamlwhennotificationsis on, and prints thenotifications:installcommand that finishes OneSignal setup. - Runs
dart format .on the host project.
Every injection is idempotent: a second run does not duplicate a registration. Pass --force to overwrite files the command already generated (it also replaces app_service_provider.dart instead of injecting into it). --dry-run is not a full preview: it stages the file writes without writing them, but the in-place edits of main.dart, kernel.dart, the route provider, AppServiceProvider, the translations and pubspec.yaml still run. The other commands (starter:configure, starter:doctor, starter:publish, starter:uninstall) are documented in CLI Commands.
Registering the Service Provider#
The injected section of lib/config/app.dart looks like this:
import 'package:magic/magic.dart';
import 'package:magic_starter/magic_starter.dart'; // injected by install
final appConfig = {
'app': {
'name': Env.get('APP_NAME', 'My App'),
'providers': [
(app) => RouteServiceProvider(app),
(app) => AppServiceProvider(app),
(app) => MagicStarterServiceProvider(app), // injected by install
],
},
};
MagicStarterServiceProvider binds MagicStarterManager under the 'magic_starter' key and defines the starter.* Gate abilities; see Service Provider.
Injecting the Config Factory#
The config factory is added to Magic.init() in lib/main.dart:
import 'package:material_ui/material_ui.dart';
import 'package:magic/magic.dart';
import 'config/app.dart';
import 'config/magic_starter.dart'; // injected by install
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Magic.init(
configFactories: [
() => appConfig,
() => magicStarterConfig, // injected by install
],
);
runApp(MagicApplication(title: 'My App'));
}
The generated lib/config/magic_starter.dart and every key in it are described in Configuration.
Bootstrapping the Starter#
Registering the provider is not enough. The starter also needs four host-owned things: how to build your user model, how to log out, which locales to offer and, when teams is on, how to read and switch teams. MagicStarter.bootstrap() registers them in one call from AppServiceProvider.boot(); the installer writes it for you.
class AppServiceProvider extends ServiceProvider {
AppServiceProvider(super.app);
@override
void register() {}
@override
Future<void> boot() async {
MagicStarter.bootstrap(
userFactory: (data) => User.fromMap(data),
onLogout: () async {
await Auth.logout();
MagicRoute.to('/auth/login');
},
locales: {
'en': 'English',
'tr': 'Türkçe',
},
);
}
}
That is the complete setup for a teamless app. With magic_starter.features.teams on, pass the three team callbacks as well:
MagicStarter.bootstrap(
userFactory: (data) => User.fromMap(data),
onLogout: () async => Auth.logout(),
locales: {
'en': 'English',
'tr': 'Türkçe',
},
currentTeam: () => User.current.currentTeam?.toMagicStarterTeam(),
allTeams: () =>
User.current.allTeams.map((t) => t.toMagicStarterTeam()).toList(),
onSwitch: (id) => MagicStarter.switchTeam('$id'),
);
The team callbacks are a group: pass all three or none.
| Situation | Result |
|---|---|
| Teams off, team callbacks omitted | Valid. No team resolver is registered and no team UI renders. |
| Teams on, all three callbacks passed | Valid. The team selector, team switching and team settings work. |
| Teams on, team callbacks omitted | Throws a StateError naming the missing call and the config flag. |
| Only some of the three callbacks passed | Throws an ArgumentError; the manager is left untouched. |
bootstrap() also takes the optional onLogin and onGuestClaimed callbacks, described in Manager, and applyAnalyticsOptOut, which the analytics feature needs (see Analytics Preference Callback).
The individual setters (useUserModel(), useLogout(), useLocaleOptions(), useTeamResolver()) stay public. Call one after bootstrap() to replace what it registered, for example to register the team resolver once your own team store is warm:
MagicStarter.useTeamResolver(
currentTeam: () => TeamStore.instance.current?.toMagicStarterTeam(),
allTeams: () => TeamStore.instance.all,
onSwitch: (id) => TeamStore.instance.switchTo(id),
);
bootstrap() covers the identity contract only. The optional presentation setters (useNavigation(), useTheme(), useWindTheme(), useHeader(), useSocialAuth() and the per-surface theme setters) stay separate and are called alongside it.
Related Documentation#
- Configuration: feature toggles, route prefixes and identity modes.
- CLI Commands: every
starter:*command and flag. - Manager: the registrations
AppServiceProvider.boot()makes. - View Registry: overriding a screen.
- Magic installation guide: scaffolding the host app.