flamingo_generator 0.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

flamingo_generator #

Automatically generate code for converting flamingo JSON by annotating Dart classes.

import 'package:flamingo/flamingo.dart';
import 'package:flamingo_annotation/flamingo_annotation.dart';

import 'cart.dart';
import 'item.dart';

part 'user.flamingo.dart';

class User extends Document<User> {
  User({
    String id,
    DocumentSnapshot snapshot,
    Map<String, dynamic> values,
  }) : super(id: id, snapshot: snapshot, values: values) {
    item = Collection(this, UserFieldValueKey.item.value);
  }

  @Field()
  String name;

  @Field(isWriteNotNull: false)
  String profile;

  @Field()
  Map<String, int> intMap;

  @Field()
  List<Map<String, int>> listIntMap;

  @Field()
  Increment<int> point = Increment('point');

  @Field()
  Increment<double> score = Increment('score');

  @ModelField()
  Cart cartA;

  @ModelField(isWriteNotNull: false)
  Cart cartB;

  @ModelField()
  List<Cart> carts;

  @StorageField()
  StorageFile fileA;

  @StorageField(isWriteNotNull: false, folderName: 'image')
  StorageFile fileB;

  @StorageField()
  List<StorageFile> filesA;

  @StorageField(isWriteNotNull: false)
  List<StorageFile> filesB;

  @SubCollection()
  Collection<Item> item;

  @override
  Map<String, dynamic> toData() => _$toData(this);

  @override
  void fromData(Map<String, dynamic> data) => _$fromData(this, data);
}

Generate the following code.

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'user.dart';

// **************************************************************************
// FieldValueGenerator
// **************************************************************************

/// FieldValueKey
enum UserFieldValueKey {
  name,
  profile,
  intMap,
  listIntMap,
  point,
  score,
  cartA,
  cartB,
  carts,
  fileA,
  fileB,
  filesA,
  filesB,
  item,
}

extension UserFieldValueKeyExtension on UserFieldValueKey {
  String get value {
    switch (this) {
      case UserFieldValueKey.name:
        return 'name';
      case UserFieldValueKey.profile:
        return 'profile';
      case UserFieldValueKey.intMap:
        return 'intMap';
      case UserFieldValueKey.listIntMap:
        return 'listIntMap';
      case UserFieldValueKey.point:
        return 'point';
      case UserFieldValueKey.score:
        return 'score';
      case UserFieldValueKey.cartA:
        return 'cartA';
      case UserFieldValueKey.cartB:
        return 'cartB';
      case UserFieldValueKey.carts:
        return 'carts';
      case UserFieldValueKey.fileA:
        return 'fileA';
      case UserFieldValueKey.fileB:
        return 'fileB';
      case UserFieldValueKey.filesA:
        return 'filesA';
      case UserFieldValueKey.filesB:
        return 'filesB';
      case UserFieldValueKey.item:
        return 'item';
      default:
        return toString();
    }
  }
}

/// For save data
Map<String, dynamic> _$toData(User doc) {
  final data = <String, dynamic>{};
  Helper.writeNotNull(data, 'name', doc.name);
  Helper.write(data, 'profile', doc.profile);
  Helper.writeNotNull(data, 'intMap', doc.intMap);
  Helper.writeNotNull(data, 'listIntMap', doc.listIntMap);
  Helper.writeIncrement(data, doc.point);
  Helper.writeIncrement(data, doc.score);

  Helper.writeModelNotNull(data, 'cartA', doc.cartA);
  Helper.writeModel(data, 'cartB', doc.cartB);
  Helper.writeModelListNotNull(data, 'carts', doc.carts);

  Helper.writeStorageNotNull(data, 'fileA', doc.fileA, isSetNull: false);
  Helper.writeStorage(data, 'image', doc.fileB, isSetNull: false);
  Helper.writeStorageListNotNull(data, 'filesA', doc.filesA, isSetNull: false);
  Helper.writeStorageList(data, 'filesB', doc.filesB, isSetNull: false);

  return data;
}

/// For load data
void _$fromData(User doc, Map<String, dynamic> data) {
  doc.name = Helper.valueFromKey<String>(data, 'name');
  doc.profile = Helper.valueFromKey<String>(data, 'profile');
  doc.intMap = Helper.valueMapFromKey<String, int>(data, 'intMap');
  doc.listIntMap = Helper.valueMapListFromKey<String, int>(data, 'listIntMap');
  doc.point = Helper.valueFromIncrement<int>(data, doc.point.fieldName);
  doc.score = Helper.valueFromIncrement<double>(data, doc.score.fieldName);

  final _cartA = Helper.valueMapFromKey<String, dynamic>(data, 'cartA');
  if (_cartA != null) {
    doc.cartA = Cart(values: _cartA);
  } else {
    doc.cartA = null;
  }

  final _cartB = Helper.valueMapFromKey<String, dynamic>(data, 'cartB');
  if (_cartB != null) {
    doc.cartB = Cart(values: _cartB);
  } else {
    doc.cartB = null;
  }

  final _carts = Helper.valueMapListFromKey<String, dynamic>(data, 'carts');
  if (_carts != null) {
    doc.carts =
        _carts.where((d) => d != null).map((d) => Cart(values: d)).toList();
  } else {
    doc.carts = null;
  }

  doc.fileA = Helper.storageFile(data, 'fileA');
  doc.fileB = Helper.storageFile(data, 'image');
  doc.filesA = Helper.storageFiles(data, 'filesA');
  doc.filesB = Helper.storageFiles(data, 'filesB');
}

0.3.2 #

Bug fix.

0.3.1 #

Updated plugin.

0.3.0 #

Renamed field value key.

0.2.0 #

Added description.

0.1.0 #

Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: const Center(
          child: Text('Hello'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flamingo_generator: ^0.3.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flamingo_generator/flamingo_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flamingo_generator that is a package requiring null.

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:flamingo_generator/flamingo_generator.dart that imports:
  • package:flamingo_generator/src/field_value_generator.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/field_value_generator.dart. (-0.50 points)

Analysis of lib/src/field_value_generator.dart reported 1 hint:

line 112 col 10: This function has a return type of 'String', but doesn't end with a return statement.

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
analyzer ^0.39.4 0.39.12
build ^1.2.2 1.3.0
code_builder ^3.2.1 3.4.0
flamingo_annotation ^0.3.0 0.3.0
flutter 0.0.0
source_gen ^0.9.5 0.9.5
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.2
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
fixnum 0.10.11
glob 1.2.0
html 0.14.0+3
js 0.6.2
logging 0.11.4
matcher 0.12.8
meta 1.1.8 1.2.1
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.0 1.9.1
pub_semver 1.4.4
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
flutter_test
pedantic_mono any