hn_easy_model 0.0.2

  • Readme
  • Changelog
  • Installing
  • 49

hn_easy_model #

中文🇨🇳

A more easy way to do Flutter JSON serialization and deserialization.

Installation #

Add a dependency on hn_easy_model in your pubspec.

dependencies:
    hn_easy_model: any
    build_runner: any

Usage #

Initialization #

0x11

Create a dart file to aggregate headers. For example you created a dart file named easy_model_headers.dart.

0x12

Create a file named build.yaml,in the same path with pubspec.yaml. The content is as follows. lib/easy_model_headers.dart replace with right path.

targets:
  $default:
    builders:
      hn_easy_model:
        generate_for:
          - lib/easy_model_headers.dart 

0x13

Switch to the command line run flutter packages pub run build_runner build. It will create a file named easy_model_headers.hneasymodel.dart.

0x14

At the beginning of the program import previous file import 'easy_model_headers.hneasymodel.dart';. Execute code initializeEasyModel();

Use model #

0x21

Model must extends HNEasyModel and annotation model with @hn_easy_model.

@hn_easy_model
class Person extends HNEasyModel {
  int age;
  double weight;
  String name;
  bool married;
  Person mother;
  Person father;
  List<Person>friends;
}

0x22 json to model

Use hn_easyInitFromJson method, example model().hn_easyInitFromJson(map);

0x23 model to json

Use hn_easyToJson method, example model.hn_easyToJson();

0x24

While model change you need run flutter packages pub run build_runner build. If there is an error you can run flutter packages pub run build_runner build --delete-conflicting-outputs or just delete easy_model_headers.hneasymodel.dart file.

Supported #

  • [x] int
  • [x] double
  • [x] bool
  • [x] String
  • [x] Custom model (need annotation with@hn_easy_model)
  • [x] Map (cannot specify type)
  • [x] List (you need specify type,support custom model annotation with @hn_easy_model)
  • [x] var dynamic (only support int、double、bool、String)

Author #

zhnnnnn, coderZhangHuiNan@163.com

License #

hn_easy_model is available under the MIT license. See the LICENSE file for more info.

[0.0.1] - hello world #

[0.0.2] - update readme #

Use this package as a library

1. Depend on it

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


dependencies:
  hn_easy_model: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:hn_easy_model/hn_easy_model.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
85
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
49
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:

  • hn_easy_model that is a package requiring null.

Health suggestions

Fix lib/hn_easy_model_builder.dart. (-10.44 points)

Analysis of lib/hn_easy_model_builder.dart reported 22 hints, including:

line 34 col 1: Avoid using braces in interpolation when not needed.

line 41 col 3: Avoid using braces in interpolation when not needed.

line 112 col 28: Avoid using braces in interpolation when not needed.

line 114 col 24: Avoid using braces in interpolation when not needed.

line 115 col 24: Avoid using braces in interpolation when not needed.

Fix lib/hn_easy_model.dart. (-4.89 points)

Analysis of lib/hn_easy_model.dart reported 10 hints, including:

line 10 col 11: Name non-constant identifiers using lowerCamelCase.

line 17 col 8: Name non-constant identifiers using lowerCamelCase.

line 23 col 7: Name non-constant identifiers using lowerCamelCase.

line 35 col 5: Don't explicitly initialize variables to null.

line 49 col 7: Name types using UpperCamelCase.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and hn_easy_model.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.39.8 0.39.12
build ^1.3.0 1.3.0
build_runner ^1.10.0 1.10.0
flutter 0.0.0
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.2
build_config 0.4.2
build_daemon 2.1.4
build_resolvers 1.3.10
build_runner_core 5.2.0 6.0.0
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
checked_yaml 1.0.2
code_builder 3.4.0
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
graphs 0.2.0
html 0.14.0+3
http_multi_server 2.2.0
http_parser 3.1.4
io 0.3.4
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
meta 1.1.8 1.2.1
mime 0.9.6+3
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
pool 1.4.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
shelf 0.7.7
shelf_web_socket 0.2.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
stream_transform 1.2.0
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
watcher 0.9.7+15
web_socket_channel 1.1.0
yaml 2.2.1
Dev dependencies
flutter_test