enum_to_string 2.2.1 copy "enum_to_string: ^2.2.1" to clipboard
enum_to_string: ^2.2.1 copied to clipboard

Better conversion of ENUMs to string. Dart has annoying EnumName.ValueName syntax when calling enum.toString, this package fixes that.

example/main.dart

import 'package:enum_to_string/enum_to_string.dart';

// ignore: constant_identifier_names
enum TestEnum { ValueOne, Value2, valueThree }

void main() {
  // Parse enum to a string
  EnumToString.convertToString(TestEnum.ValueOne); //ValueOne
  EnumToString.convertToString(TestEnum.Value2); //Value2
  EnumToString.convertToString(TestEnum.valueThree); //valueThree

  // Parse an enum to something more human readable
  EnumToString.convertToString(TestEnum.ValueOne); //Value one
  EnumToString.convertToString(TestEnum.Value2); //Value 2
  EnumToString.convertToString(TestEnum.valueThree); //Value three

  // Get an enum from a string
  EnumToString.fromString(TestEnum.values, 'ValueOne'); //, TestEnum.ValueOne
  EnumToString.fromString(TestEnum.values, 'Value2'); // TestEnum.Value2
  EnumToString.fromString(TestEnum.values, 'valueThree'); // TestEnum.valueThree

  // Get an enum from a string
  EnumToString.toList<TestEnum>(
      TestEnum.values); // {ValueOne, Value2, valuethree}

  EnumToString.fromList(TestEnum.values, ['valueOne', 'Value2', 'alksdfjsda']);
  //[TestEnum.ValueOne, TestEnum.Value2, null]
}
copied to clipboard
326
likes
160
points
156k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.15 - 2025.03.30

Better conversion of ENUMs to string. Dart has annoying EnumName.ValueName syntax when calling enum.toString, this package fixes that.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

More

Packages that depend on enum_to_string