2

I want to change the primary color in my app so I tried:

theme: ThemeData(
        primaryColor: const Color(0xFF784CEF),
),

but that didn't work so I checked the documentation I found another way of doing it which is using

colorScheme: ColorScheme.fromSwatch(
    primarySwatch: Colors.red,
    // but I want 0xFF784CEF as my primary color so I tried
    // primarySwatch: Color(0xFF784CEF), 
    // which gives me an error saying `The argument type 'Color' can't be assigned to the parameter type 'MaterialColor'.`
),

So my question is: how to change the primary color with a hexadecimal color

AzerSD
  • 148
  • 1
  • 9

1 Answers1

6

On MaterialApp theme

theme: Theme.of(context).copyWith(
  colorScheme: Theme.of(context).colorScheme.copyWith(
        primary: const Color(0xFF784CEF),
      ),
),
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
  • worked thanks for your help. but you said 'On `MaterialApp` `theme`', I've been looking for that page but found nth. can you please provide the link you took the code from? – AzerSD Jan 01 '22 at 13:45
  • 1
    I follow the concept of [extending-the-parent-theme](https://docs.flutter.dev/cookbook/design/themes#extending-the-parent-theme) and while we are suggested to use `colorScheme` I follow this approach. – Md. Yeasin Sheikh Jan 01 '22 at 13:50