1

I am using GetX with Flutter and dynamically change Application theme via standard ThemeData. All is working great for properties within ThemeData.

However, I just implemented Drawer widget and wanted to also theme the 'decoration' property within DrawerHeader (of type BoxDecoration). I wanted to theme the color within BoxDecoration depending on selected theme but it only seems to accept constant. I have not find any way to dynamically change it based on the theme.

return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: const <Widget>[
          DrawerHeader(
            decoration:
                BoxDecoration(color: Get.isDarkMode ? Colors.red : Colors.blue),

I get the following error:

The values in a const list literal must be constants. Try removing the keyword 'const' from the list literal.

It relates to the following part: color: Get.isDarkMode ? Colors.red : Colors.blue

Any recommendation how to do that?

Thank you.

mmerlin10
  • 31
  • 5

2 Answers2

1

Felipe - you are right. I spent hours of reading and testing but for some reason I completely missed the obvious thing - was always looking only at Decoration / BoxDecoration itself and not up the tree. Thank you so much for your fast answer. It works now.

Issue was with the following line: children: const <Widget>[

after removing the const it works - solution:

children: <Widget>[

mmerlin10
  • 31
  • 5
0

Render two different drawer headers based on Get.color, instead of rendering one drawer head with variable colors.

Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49