xyz_gen 0.40.1 copy "xyz_gen: ^0.40.1" to clipboard
xyz_gen: ^0.40.1 copied to clipboard

This package is designed to help speed up your development journey by generating boilerplate code for your projects.

example/example.dart

//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Your Project Name
// Copyright Ⓒ Your Name
//
// Licensing details can be found in the LICENSE file in the root directory.
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~

import 'dart:convert';

import 'package:xyz_gen_annotations/xyz_gen_annotations.dart';

part '_model_user.g.dart';

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

// This is just one of many generators included in the `xyz_gen` package! This
// Model generator is much more flexible than `json_serializable` and easier
// to use in your project.

@GenerateModel(
  fields: {
    "email": $LowerCaseString,
    "searchable_name": $LowerCaseString,
    "display_name": "String?",
    "type": $UpperSnakeCaseString,
  },
  shouldInherit: true,
  keyStringCase: "lower_snake_case",
)
// ignore: unused_element
abstract class _ModelUser extends ThisModel<ModelUser> {
  @Field()
  String? firstName;

  @Field()
  String? lastName;

  String get fullName => "$firstName $lastName";

  bool get isAdmin => this.model.type == ModelUserType.ADMIN.name;
  bool get isUser => this.model.type == ModelUserType.USER.name;

  bool emailContains(String value) {
    return this.model.email?.contains(value.toLowerCase()) == true;
  }

  bool nameContains(String value) {
    return this.model.searchableName?.contains(value.toLowerCase()) == true;
  }
}

enum ModelUserType {
  ADMIN,
  USER,
}
8
likes
0
points
415
downloads

Publisher

unverified uploader

Weekly Downloads

This package is designed to help speed up your development journey by generating boilerplate code for your projects.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, args, collection, path, xyz_gen_annotations, xyz_utils

More

Packages that depend on xyz_gen