flutter-tips-and-tricks icon indicating copy to clipboard operation
flutter-tips-and-tricks copied to clipboard

"Classes as enums" tip is obsolete

Open orevial opened this issue 3 years ago • 1 comments
trafficstars

Using classes as enum has become obsolete since Dart 2.17, this tip could be removed !

https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/classes-as-enums-in-dart/classes-as-enums-in-dart.md

orevial avatar Aug 26 '22 11:08 orevial

also, it could be cleaner done through extension, i.e.

enum AnimalType{ dog, cat, parrot };

extension on AnimalType {
  static const _foodTypes =['meat', 'fish', 'fruit'];
  String get foodType => _foodTypes[index];
}

which could still be useful, if it's some local ui property, specific to current widget.

misterfourtytwo avatar Jan 27 '23 18:01 misterfourtytwo