time_group_enum.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // AUTO-GENERATED FILE, DO NOT MODIFY!
  3. //
  4. // @dart=2.12
  5. // ignore_for_file: unused_element, unused_import
  6. // ignore_for_file: always_put_required_named_parameters_first
  7. // ignore_for_file: constant_identifier_names
  8. // ignore_for_file: lines_longer_than_80_chars
  9. part of openapi.api;
  10. class TimeGroupEnum {
  11. /// Instantiate a new enum with the provided [value].
  12. const TimeGroupEnum._(this.value);
  13. /// The underlying value of this enum member.
  14. final String value;
  15. @override
  16. String toString() => value;
  17. String toJson() => value;
  18. static const day = TimeGroupEnum._(r'day');
  19. static const month = TimeGroupEnum._(r'month');
  20. /// List of all possible values in this [enum][TimeGroupEnum].
  21. static const values = <TimeGroupEnum>[
  22. day,
  23. month,
  24. ];
  25. static TimeGroupEnum? fromJson(dynamic value) => TimeGroupEnumTypeTransformer().decode(value);
  26. static List<TimeGroupEnum>? listFromJson(dynamic json, {bool growable = false,}) {
  27. final result = <TimeGroupEnum>[];
  28. if (json is List && json.isNotEmpty) {
  29. for (final row in json) {
  30. final value = TimeGroupEnum.fromJson(row);
  31. if (value != null) {
  32. result.add(value);
  33. }
  34. }
  35. }
  36. return result.toList(growable: growable);
  37. }
  38. }
  39. /// Transformation class that can [encode] an instance of [TimeGroupEnum] to String,
  40. /// and [decode] dynamic data back to [TimeGroupEnum].
  41. class TimeGroupEnumTypeTransformer {
  42. factory TimeGroupEnumTypeTransformer() => _instance ??= const TimeGroupEnumTypeTransformer._();
  43. const TimeGroupEnumTypeTransformer._();
  44. String encode(TimeGroupEnum data) => data.value;
  45. /// Decodes a [dynamic value][data] to a TimeGroupEnum.
  46. ///
  47. /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
  48. /// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
  49. /// cannot be decoded successfully, then an [UnimplementedError] is thrown.
  50. ///
  51. /// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
  52. /// and users are still using an old app with the old code.
  53. TimeGroupEnum? decode(dynamic data, {bool allowNull = true}) {
  54. if (data != null) {
  55. switch (data.toString()) {
  56. case r'day': return TimeGroupEnum.day;
  57. case r'month': return TimeGroupEnum.month;
  58. default:
  59. if (!allowNull) {
  60. throw ArgumentError('Unknown enum value to decode: $data');
  61. }
  62. }
  63. }
  64. return null;
  65. }
  66. /// Singleton [TimeGroupEnumTypeTransformer] instance.
  67. static TimeGroupEnumTypeTransformer? _instance;
  68. }