Here we will see how to set app theme globally so that you can access from anywhere from your app. With this you are also able set them in the MaterialApp().
Here we will call a class name AppTheme and put the code below
class AppTheme{
static ThemeData appThemeData = ThemeData(
brightness: Brightness.light,
appBarTheme: const AppBarTheme(
elevation: 0,
centerTitle: true,
backgroundColor: Colors.white,
iconTheme: IconThemeData(
color: AppColors.primaryText
)
)
);
}
Here you see the variable appThemeData is an object of ThemeData(). Inside the ThemeData(), we do the actual settings. The class returns an instance and we save it appThemeData.
At the same time, you see the wrapper class name is AppTheme.
The variable appThemeData will be called main.dart class. Let’s see the code
See here how we called appThemeData using AppTheme class from MaterialApp()