toMap method

Map<String, dynamic>? toMap()

Implementation

Map<String, dynamic>? toMap() {
  final colors = _customs.entries
      .map((e) {
        if (e.value == null) return null;
        return ColorThemeData(name: e.key, config: e.value!).toMap();
      })
      .where((e) => e != null)
      .toList();
  final gradients = _gradients.entries
      .map((e) {
        if (e.value == null) return null;
        return GradientThemeData(name: e.key, config: e.value!).toMap();
      })
      .where((e) => e != null)
      .toList();
  final x = {
    "themeMode": _themeMode?.toString(),
    "green": _green?.toJson(),
    "grey": _grey?.toJson(),
    "blue": _blue?.toJson(),
    "red": _red?.toJson(),
    "orange": _orange?.toJson(),
    "yellow": _yellow?.toJson(),
    "purple": _purple?.toJson(),
    "pink": _pink?.toJson(),
    ..._colors.map((key, value) {
      return MapEntry(key, value?.toMap());
    }),
    if (colors.isNotEmpty) "colors": colors,
    if (gradients.isNotEmpty) "gradients": gradients,
  };
  final y = x.entries.where((e) {
    if (e.value == null) return false;
    return true;
  });
  if (y.isEmpty) return null;
  return Map.fromEntries(y);
}