enum_to_string 1.0.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 97

enum_to_string #

Build Status

Better conversion of ENUMs to string - It also can handle converting back again!

What it does #

It takes an enum such as:

enum TestEnum { testValue1 }

and converts it to

testValue1

Also handles camel case

Input enum TestEnum { testValue1 } Output Test Value 1

Usage #

import 'package:enum_to_string:enum_to_string.dart';

enum TestEnum { testValue1, testValue2 };

convert(){
    String result = EnumToString.parse(TestEnum.testValue1);
    //result = 'testValue1'

    String resultCamelCase = EnumToString.parseCamelCase(TestEnum.testValue1);
    //result = 'Test Value 1'

    final result = EnumToString.fromString(TestEnum.values, "testValue1");
    // TestEnum.testValue1

    EnumToString.toList(TestEnum.values);
    //result = 'testValue1','testValue2',
}

Any pull requests / extensions welcome, this was just an annoying thing I needed to fix a couple of times so viola! a package was born.

[1.0.9] - 2020-02-21 #

  • Added .toList function (Thanks @CodeGrue)

[1.0.8] - 2019-11-03 #

  • Better type handling in fromString method (Thanks @Sergey-Schirmer)

[1.0.7+1] - 2019-10-21 #

  • Improving code robustness (Thanks @ewertonrp)

[1.0.7] - 2019-05-30 #

  • Improving examples

[1.0.6] - 2019-05-30 #

  • Added support for getting an enum from a string

[1.0.5] - 2019-05-29 #

  • Better readme formatting

[1.0.4] - 2019-05-29 #

  • Better handling of null types

[1.0.3] - 2019-05-26 #

  • Adding explicit types

[1.0.2] - 2019-05-24 #

  • Improving my dart score

[1.0.1] - 2019-05-24 #

  • Initial library release

example/main.dart

import 'package:enum_to_string/enum_to_string.dart';

enum TestEnum { ValueOne, Value2, valueThree }

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

  // Parse an enum to something more human readable
  EnumToString.parseCamelCase(TestEnum.ValueOne); //Value one
  EnumToString.parseCamelCase(TestEnum.Value2); //Value 2
  EnumToString.parseCamelCase(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}
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  enum_to_string: ^1.0.9

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:enum_to_string/enum_to_string.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
95
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test any