Advatanges and disadvantages of using theme extensions for storing colors instead of class

Viewed 18

What are the advantages of using theme extension for storing custom colors instead of class containing static consts?

class AppColors {    
   static const Color brandColor = Color(0xFF1E88E5);
   static const Color danger = Color(0xFFE53935);
   //...
}

vs

@immutable
class MyColors extends ThemeExtension<MyColors> {
  const MyColors({
    required this.brandColor,
    required this.danger,
  });
  //...
}

//...
final MyColors myColors = Theme.of(context).extension<MyColors>()!;

One advantages for class is that it does not require context. What are the prons of theme extensions?

1 Answers

not sure, but I guess if you want to automatically toggle between night and day color schemes, you need themes - or at least it makes toggling a lot easier

Related