I want to use custom colors and themes in ThemeData. I know that I can define them in a separate file and import that file and use them. But I want those colors to work when changing the dark and light themes. Currently I have separate dark and light themes that I toggle. Is there anyway to define custom colors in dark and light ThemeData separately?
AppTheme.dart:
class AppTheme {
AppTheme._();
// Light Theme
static final ThemeData lightTheme = ThemeData.light().copyWith(
appBarTheme: AppBarTheme(
color: Colors.grey[100],
brightness: Brightness.light,
),
scaffoldBackgroundColor: Colors.white,
actionButtonColor: Colors.black, // Like this
);
// Dark Theme
static final ThemeData darkTheme = ThemeData.dark().copyWith(
appBarTheme: AppBarTheme(
color: Colors.grey[850],
brightness: Brightness.dark,
),
scaffoldBackgroundColor: Colors.grey[900],
actionButtonColor: Colors.red, // Like this
);
}
App.dart
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Dashboard(),
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
debugShowCheckedModeBanner: false,
);
}
}