fromProject method
The theme of the project's MaterialApp.
brightness picks theme or darkTheme. When null, a literal
themeMode: ThemeMode.dark selects dark; otherwise light.
Implementation
MaterialTheme fromProject(
ProjectAnalysis analysis, {
ThemeBrightness? brightness,
}) {
ObjectValue? app;
for (final w in analysis.widgets) {
app = _findApp(w.tree, 0);
if (app != null) break;
}
final fallback = MaterialTheme.baseline(
brightness ?? ThemeBrightness.light,
);
if (app == null) {
_note(
'No MaterialApp found; using the default Material 3 theme',
null,
IrSeverity.info,
);
return fallback;
}
final mode = eval.enumName(app['themeMode']);
final dark =
(brightness ?? (mode == 'dark' ? ThemeBrightness.dark : null)) ==
ThemeBrightness.dark;
var data = app['theme'];
if (dark) {
if (app['darkTheme'] != null) {
data = app['darkTheme'];
} else {
_note(
'Dark mode requested but MaterialApp has no darkTheme; using theme',
app,
IrSeverity.info,
);
}
}
if (data == null) return fallback;
return themeData(data, current: fallback);
}