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.

Share:
1,337
Jitan Gupta
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, 2023

Comments

  • Jitan Gupta
    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.
    Jahn E. over 2 years
    FYI: You need to assign the color within the BoxDecoration if you e.g. use BoxDecoration parameters like shape.