fields_generator

Last updated:

0 purchases

fields_generator Image
fields_generator Images
Add to Cart

Description:

fields generator

Fields Generator #
This package provides a Dart and Flutter field name code generation for class.
Used for #

Firebase query field name
Supabase query field name

Usage #
import 'package:fields_generator/fields_generator.dart';
import 'package:json_annotation/json_annotation.dart';

part 'main.fields.dart';

@fields()
class User {
User({
required this.name,
required this.age,
});

final String name;
final int age;
}


void main(List<String> args) {
print(UserFields.nameFieldName); // output: name
print(UserFields.ageFieldName); // output: age
}
copied to clipboard
Generated code #
// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// FieldsLibraryGenerator
// **************************************************************************

part of 'main.dart';

/// [User] fields
abstract final class UserFields {
const UserFields._();

/// [User.name]
static const String nameFieldName = 'name';

/// [User.age]
static const String ageFieldName = 'age';

static const List<String> fieldsNames = [nameFieldName, ageFieldName];
}

/// [User] fields
@JsonEnum(
fieldRename: FieldRename.none,
)
enum UserFieldsEnum {
name,
age,
}
copied to clipboard
Working with freezed #
import 'package:fields_generator/fields_generator.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'main.fields.dart';
part 'main.freezed.dart';
part 'main.g.dart';

@freezed
class User with _$User {
@fields
@JsonSerializable()
factory User({
required String name,
required int age,
}) = _User;

factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}
copied to clipboard
Features #

✅ Generate fields name for class

Getting started #
In your pubspec.yaml file, add the following dependency:
dependencies:
fields_generator:
copied to clipboard
Then, run flutter pub get in your terminal.
or run this command:
flutter pub add fields_generator
copied to clipboard
Additional information #
This package is still in development, and the API is subject to change.
feel free to contribute to this package.
License #
Read more about the license here

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.