enum_string_extension_gen 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

Provides source_gen Generator for generating enumString extension. For more info on this package check out his blog article.

enum_string_extension #

enum_string_extension_gen #

0.0.5 #

  • Add support for namespace. If a namespace is declared on one of the keys, it will be forced for all keys with the same name.

0.0.4 #

  • Fix bugs in EnumKey handling (unique, determinism) and in some code generated

0.0.3 #

  • Add support for EnumKey with prefix parameter and exclude option
  • Exclude parameter prevent code gen
  • Prefix parametr creates an changes the prefix of the text() and adds the prefix to the AppLocalization fields

0.0.2 Fix multiple enum and support subtypes for List<T> #

  • Fix bug that prevented multiple enum to generate code
  • Add support for types inside lists

0.0.1 Initial release #

  • Lets you annotate an object using @enumString to generate a enumString extension

example/example.dart

import 'dart:ui' show Locale;

import 'package:enum_string_extension/enum_string_extension.dart';
import 'package:flutter/cupertino.dart' show Localizations, BuildContext;
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart' show immutable;

part 'basic_class.g.dart';

// The localizations delagate must be called AppLocalizations and implement each field of the enum
class AppLocalizations {
  AppLocalizations(this.locale) : labels = languages[locale];

  final Locale locale;
  static final Map<Locale, AppLocalizationsLabels> languages = <Locale, AppLocalizationsLabels>{
    const Locale.fromSubtags(languageCode: 'en', countryCode: 'US'): const AppLocalizationsLabels(
      value1: 'Value 1 in english',
      value2: 'Value 2 in english',
      value3: 'Value 3 in english',
      testValue1: 'TestValue 1 in english',
      testValue2: 'TestValue 2 in english',
      test2Value1: 'Test2Value 1 in english',
      test2Value2: 'Test2Value 2 in english',
      myTestValue1: 'TestValue 1 in english',
      myTestValue2: 'TestValue 2 in english',
      mySecondTestValue1: 'TestValue 1 in english',
      mySecondTestValue2: 'TestValue 2 in english',
      myNamespace: AppLocalizations_Labels_myNamespace(
        value1: 'Value 1 in english',
        value2: 'Value 2 in english',
        value3: 'Value 3 in english',
        nameTestValue1: 'Value 1 in english',
        nameTestValue2: 'Value 2 in english',
        nameTestValue3: 'Value 3 in english',
      ),
    )
  };

  final AppLocalizationsLabels labels;

  static AppLocalizationsLabels of(BuildContext context) =>
      Localizations.of<AppLocalizations>(context, AppLocalizations)?.labels;
}

class AppLocalizations_Labels_myNamespace {
  const AppLocalizations_Labels_myNamespace({
    this.value1,
    this.value2,
    this.value3,
    this.nameTestValue1,
    this.nameTestValue2,
    this.nameTestValue3,
  });

  final String value1;
  final String value2;
  final String value3;
  final String nameTestValue1;
  final String nameTestValue2;
  final String nameTestValue3;
}

class AppLocalizationsLabels {
  const AppLocalizationsLabels({
    this.value1,
    this.value2,
    this.value3,
    this.testValue1,
    this.testValue2,
    this.test2Value1,
    this.test2Value2,
    this.myTestValue1,
    this.myTestValue2,
    this.mySecondTestValue1,
    this.mySecondTestValue2,
    this.variantValue5,
    this.variantValue6,
    this.myNamespace,
  });

  final String value1;
  final String value2;
  final String value3;
  final String testValue1;
  final String testValue2;
  final String test2Value1;
  final String test2Value2;
  final String myTestValue1;
  final String myTestValue2;
  final String mySecondTestValue1;
  final String mySecondTestValue2;
  final String variantValue5;
  final String variantValue6;
  final AppLocalizations_Labels_myNamespace myNamespace;
}

enum TestEnum4 {
  value1,
  value3,
}

enum TestEnum3 {
  value5,
  value6,
}

enum TestEnum2 {
  value1,
  value2,
  value3,
}

enum TestEnum6 {
  value1,
  value2,
  value3,
}

enum TestEnum {
  value1,
  value2,
}

@immutable
@enumString
class BasicClass {
  const BasicClass({
    this.test,
    this.test2,
    this.test3,
    this.test4,
    this.test5,
    this.test6,
    this.test7,
    this.test20,
    this.test21,
    this.test22,
    this.test23,
    this.test24,
    this.test25,
    this.test26,
  });

  // Should generate text() for TestEnum
  final TestEnum test;
  // Should generate text() TestEnum2
  final TestEnum2 test2;
  // Should generate variantText() for TestEnum3 - not the text()
  @EnumKey(prefix: 'variant')
  final List<TestEnum3> test3;

  // Should generate myTestText() for TestEnum - ignore other annotations
  @JsonKey(ignore: true)
  @EnumKey(prefix: 'myTest')
  @EnumKey(prefix: 'mySecondTest')
  final TestEnum test4;
  // Should generate testText() for TestEnum
  @EnumKey(prefix: 'test2')
  final TestEnum test5;

  // Should generate text() for TestEnum6 with namespace
  @EnumKey(namespace: 'myNamespace')
  final TestEnum6 test6;
  // Should generate nameTestText() for TestEnum6 with namespace
  @EnumKey(namespace: 'myNamespace', prefix: 'nameTest')
  final TestEnum6 test7;

  // Should not generate code

  // Duplicate prefix
  final TestEnum test20;
  // Should not generate duplicate text() for TestEnum
  @EnumKey(prefix: 'test')
  final TestEnum test21;
  @EnumKey(prefix: 'Test')
  final TestEnum test22;
  // Not enum fields
  final String test23;
  final List<String> test24;
  // Excluded enum
  @EnumKey(exclude: true)
  final TestEnum4 test25;

  // Should not generate nameTestText() for TestEnum6 without the namespace previously declared
  @EnumKey(prefix: 'nameTest')
  final TestEnum6 test26;
}

Use this package as a library

1. Depend on it

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


dependencies:
  enum_string_extension_gen: ^0.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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_string_extension_gen/enum_string_extension_gen.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on May 30, 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

Health suggestions

Format lib/src/enum_string_extension_gen.dart.

Run dartfmt to format lib/src/enum_string_extension_gen.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
analyzer >=0.39.0 <1.0.0 0.39.8
build >=1.0.0 <2.0.0 1.3.0
enum_string_extension >=0.0.5 <2.0.0 0.0.5
logging >=0.0.0 <1.0.0 0.11.4
source_gen >=0.9.0 <1.0.0 0.9.5
Transitive dependencies
_fe_analyzer_shared 3.0.0
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner >=1.0.0 <2.0.0
build_test <1.0.0
test <2.0.0