mohammad
mohammad

Reputation: 2900

custom color for different ThemeData in flutter

I want to define a themeData for light theme and another one for dark theme.

but my problem is that I don't know how to define my own custom color for each themeData like badgeColor, CarColor,... image

I am searching alot and confused how to do that?

any help is appreciated.

Upvotes: 5

Views: 3299

Answers (2)

mohammad
mohammad

Reputation: 2900

the solution was:

import 'package:flutter/material.dart';

extension ColorSchemeExtension on ColorScheme {
  Color get warning => this.brightness == Brightness.light
      ? const Color(0xFF28a745)
      : const Color(0xFF28a745);
}

Upvotes: 13

CopsOnRoad
CopsOnRoad

Reputation: 267434

In MaterialApp, you have theme, darkTheme and themeMode property, make use of them.

MaterialApp(
  theme: ThemeData(
    // provide light theme colors
  ), 
  darkTheme: ThemeData(
    // provide dark theme colors
  ), 
  themeMode: ThemeMode.system, // depending on this, either light or dark theme will be used
);

Upvotes: 1

Related Questions