How to set the color based on dark / light theme?
1,337
In your root file (main.dart
) your entry point of the app is located. In general, you have a class MyApp
which returns a MaterialApp
widget. This out-of-the-box widget from the Flutter SDK lets you define your app´s theme. Here you can define the theme.
In your Container, you can assign the color directly via the color parameter. To refer to your theme data do this: Theme.of(context).backgroundColor
for example.
Author by
Jitan Gupta
An enthusiast software developer with experience in various technologies like ASP.Net MVC, C#, SQL, Entity Framework, Linq, Angular, Bootstrap. I love writing poetry, stories, and storytelling apart from coding.
Updated on January 01, 2023Comments
-
Jitan Gupta over 1 year
I want to set a dark and a light color scheme and use it as a background color of containers.
Here is my code:
Container( padding: const EdgeInsets.all(kDefaultPadding), //change required here: decoration: const BoxDecoration(color: kDarkColor), child: ... , )
-
Jahn E. over 2 yearsFYI: You need to assign the color within the BoxDecoration if you e.g. use BoxDecoration parameters like shape.