mainDartContent static method
Generates the lib/main.dart bootstrap file.
Produces a full main.dart with WidgetsFlutterBinding.ensureInitialized(),
Magic.init() with dynamic config factories, and MagicApplication.
Stub loading is routed through the per-install StubDriver supplied by
the caller (the active InstallContext's stubs field) and an explicit
searchPaths list pointing at magic's bundled assets/stubs/. The
static StubLoader defaults resolve to fluttersdk_artisan's own
assets/stubs/, where magic-only stubs do not exist; routing through
the driver preserves multi-publisher correctness and lets in-memory test
drivers serve fixture content without touching the host filesystem.
stubs — the active StubDriver (production: RealStubDriver;
tests: an in-memory fixture driver). Required so resolution honours
the magic-side stub bundle rather than the substrate's default.
searchPaths — directories to search before the driver's defaults.
In production the caller resolves magic's stub directory via the
consumer's package_config.json and passes it here; pass null
when the test driver ignores searchPaths.
appName — the human-readable application name (e.g. My App).
configImports — list of import statements (one per config file).
configFactories — list of factory lambda strings (e.g. () => appConfig).
Implementation
static String mainDartContent({
required StubDriver stubs,
required String appName,
required List<String> configImports,
required List<String> configFactories,
List<String>? searchPaths,
}) {
final imports = configImports.join('\n');
final factories = configFactories.map((f) => ' $f,').join('\n');
return stubs.replace(stubs.load('install/main', searchPaths: searchPaths), {
'configImports': imports,
'configFactories': factories,
'appName': appName,
});
}