How to set Flutter app theme as to dark by default?
You need to use ThemeMode
- Describes which
theme
will be used byMaterialApp
.
SAMPLE CODE
themeMode: ThemeMode.dark,//Always use the dark mode (if available) regardless of system preference.
themeMode: ThemeMode.light,//Always use the light mode regardless of system preference.
themeMode: ThemeMode.system,//Use either the light or dark theme based on what the user has selected in the system settings.
themeMode: ThemeMode.values,//A constant List of the values in this enum, in order of their declaration.
How To use
ThemeMode
inMaterialApp
MaterialApp(
debugShowCheckedModeBanner: false,
theme:
ThemeData(primarySwatch: Colors.blue, brightness: Brightness.light),
themeMode: ThemeMode.dark,
darkTheme: ThemeData(brightness: Brightness.dark),
home: SafeArea(
child:Scaffold(
) ),
);
The recommended method is to use ColorScheme
.
var mode = ThemeMode.light; // or ThemeMode.dark
MaterialApp(
theme: ThemeData.from(colorScheme: ColorScheme.light()),
darkTheme: ThemeData.from(colorScheme: ColorScheme.dark()),
themeMode: mode,
home: //...
)