How to set the color based on dark / light theme?


I want to set a dark and a light color scheme and use it as a background color of containers.

Here is my code:

  padding: const EdgeInsets.all(kDefaultPadding),
  //change required here:
  decoration: const BoxDecoration(color: kDarkColor),
  child: ... ,


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.

Answered By – Jahn E.

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *