Flutters temasystem låter dig definiera konsistent visuell styling (färger, typsnitt, komponentstil) app-övergripande, med stöd för ljusa/mörka teman. Genom att centralisera styling via teman säkerställs konsistens och gör appar lätta att omslida.
Definiera ett tema
// define the app's theme in MaterialApp
MaterialApp(
theme: ThemeData( // LIGHT theme
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
textTheme: TextTheme(/* font styles */),
elevatedButtonTheme: /* button styling */,
useMaterial3: true,
),
darkTheme: ThemeData.dark(), // DARK theme
themeMode: ThemeMode.system, // follow the system setting (or .light/.dark)
)
