MonetColors.fromMap constructor
Creates an instance from a map of raw color names and int colors taken from the system.
Implementation
factory MonetColors.fromMap(Map<String, int> colors) {
final accent1 = <int, Color>{};
final accent2 = <int, Color>{};
final accent3 = <int, Color>{};
final neutral1 = <int, Color>{};
final neutral2 = <int, Color>{};
colors.forEach((name, value) {
/// Example color name: accent1_500
final type = name.split('_')[0];
final shade = int.parse(name.split('_')[1]);
switch (type) {
case 'accent1':
accent1[shade] = Color(value);
break;
case 'accent2':
accent2[shade] = Color(value);
break;
case 'accent3':
accent3[shade] = Color(value);
break;
case 'neutral1':
neutral1[shade] = Color(value);
break;
case 'neutral2':
neutral2[shade] = Color(value);
break;
}
});
return MonetColors(
primary: MonetColor._(accent1),
secondary: MonetColor._(accent2),
tertiary: MonetColor._(accent3),
neutral: MonetColor._(neutral1),
neutralVariant: MonetColor._(neutral2),
);
}