enum_generator 1.0.0 copy "enum_generator: ^1.0.0" to clipboard
enum_generator: ^1.0.0 copied to clipboard

retractedoutdated

This is enum_ext generator. This makes life pretty easy by generating some useful methods and properties on enum.

example/main.dart

import 'package:enum_ext/enum_ext.dart';

part 'main.g.dart';

@EnumExt()
enum HttpResponse {
  @EnumExtValue(200)
  ok,
  @EnumExtValue(404)
  notFound,
  @EnumExtValue(500)
  internalServerError,
}

void main(List<String> arguments) {
  final response = HttpResponse.internalServerError;

  print(response); // HttpResponse.ok
  print(response.name); // ok
  print(response.index); // 0
  print(response.value); // 200

  response.when(
    ok: (e) {
      // Do some actions only if the response is HttpResponse.ok
    },
    notFound: (e) {
      // Do some actions only if the response is HttpResponse.notFound
    },
    internalServerError: (e) {
      // Do some actions only if the response is HttpResponse.internalServerError
    },
  );

  response.mayBeWhen(
    ok: (e) {
      // Do some actions only if the response is HttpResponse.ok
    },
    orElse: (e) {
      // Do some actions only if the response is something other than HttpResponse.ok
    },
  );

  response.onlyWhen(
    ok: (e) {
      // Do some actions only if the response is HttpResponse.ok
    },
  );

  final value = response.map(
    ok: (e) => "Some value based on HttpResponse.ok",
    notFound: (e) => "Some value based on HttpResponse.notFound",
    internalServerError: (e) =>
        "Some value based on HttpResponse.internalServerError",
  );

  final skinType = response.mapSimply(
    ok: "Some value based on HttpResponse.ok",
    notFound: "Some value based on HttpResponse.notFound",
    internalServerError: "Some value based on HttpResponse.internalServerError",
  );

  print(response.title); // Internal Server Error
}
2
likes
0
pub points
39%
popularity

Publisher

unverified uploader

This is enum_ext generator. This makes life pretty easy by generating some useful methods and properties on enum.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, chalk, enum_ext, recase, source_gen

More

Packages that depend on enum_generator