Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/masreplay/fields_generator
Fields name generator for Dart
https://github.com/masreplay/fields_generator
codegenerator dart flutter freezed json
Last synced: 21 days ago
JSON representation
Fields name generator for Dart
- Host: GitHub
- URL: https://github.com/masreplay/fields_generator
- Owner: masreplay
- License: gpl-3.0
- Created: 2024-02-11T16:22:37.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-26T21:32:45.000Z (7 months ago)
- Last Synced: 2024-04-27T21:45:58.162Z (7 months ago)
- Topics: codegenerator, dart, flutter, freezed, json
- Language: Dart
- Homepage: https://pub.dev/packages/fields_generator
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```dart
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 args) {
print(UserFields.nameFieldName); // output: name
print(UserFields.ageFieldName); // output: age
}
```## Generated code
```dart
// 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 fieldsNames = [nameFieldName, ageFieldName];
}/// [User] fields
@JsonEnum(
fieldRename: FieldRename.none,
)
enum UserFieldsEnum {
name,
age,
}
```## Working with freezed
```dart
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 json) => _$UserFromJson(json);
}
```## Features
- [x] Generate fields name for class## Getting started
In your `pubspec.yaml` file, add the following dependency:```yaml
dependencies:
fields_generator:
```Then, run `flutter pub get` in your terminal.
or run this command:
```shell
flutter pub add fields_generator
```## 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)