jsoninflater 0.2.0

JsonInflater #

详细介绍: #

Flutter中Json序列化之--支持泛型 <br/>

如何使用 #

  1. 添加依赖:

    dev_dependencies:
      json_serializable: ^2.0.0
      jsoninflater: ^0.2.0
      build_runner: ^1.0.0
    
  2. 创建模型,添加注解JsonFlater以及mixin类。如:

    part `xxx.g.dart`;
    
    @JsonInflater()
    class TestGenerics1<K> with PartOfTestGenerics1 {
    
      String msg;
      K data;
    
      TestGenerics1(this.msg, this.data);
    
    }
    

    mixin类是代码生成的,格式是:PartOf${className}。功能是提供toJson()parse()方法。

  3. 创建一个Json工具类,添加JsonGather注解。

    @JsonGather()
    class JsonUtil {
    
    }
    

    一个项目中只能有一个JsonGather注解。

  4. 运行命令,生成代码:

    flutter packages pub run build_runner clean
    flutter packages pub run build_runner build
    
  5. 使用:

    • toJson.

      var test = JsonTest("json test");
      print(test.toJson()); // -> {msg: json test}
      
    • parse<T>()。本框架提供的一个将Map转换成模型的方法。提供5种不同泛型数量的方法:

      • parse<T>
      • parse2<T1, T2>
      • parse3<T1, T2, T3>
      • parse4<T1, T2, T3, T4>
      • parse5<T1, T2, T3, T4, T5>

      比较特殊的是,泛型需要按照如下规则:后一个泛型必须是前面泛型的泛型。如:

      T1 : List<Model<String>>
      T2 : Model<String>
      T3 : String
      

      用这样的方式解决泛型嵌套的问题。

<br/>

0.0.1 #

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

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


dependencies:
  jsoninflater: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:jsoninflater/cacheInfo.dart';
import 'package:jsoninflater/jsonGather.dart';
import 'package:jsoninflater/jsonInflater.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
2
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
42
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: other

Platform components identified in package: build, io, mirrors.

Health suggestions

Fix lib/jsonInflater.dart. (-1.49 points)

Analysis of lib/jsonInflater.dart reported 3 hints:

line 68 col 9: Use isNotEmpty instead of length

line 144 col 9: Use isNotEmpty instead of length

line 208 col 10: Use isNotEmpty instead of length

Fix lib/jsonGather.dart. (-0.50 points)

Analysis of lib/jsonGather.dart reported 1 hint:

line 21 col 9: Use isEmpty instead of length

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (json_annotation, json_serializable).

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.

None of the files in the package's example/ directory matches known example patterns.

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

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
build_runner ^1.0.0 1.6.2
json_annotation ^2.0.0 2.3.0 2.4.0
json_serializable ^2.0.0 2.3.0 3.1.0
Transitive dependencies
analyzer 0.36.4 0.37.0
args 1.5.2
async 2.3.0
build 1.1.5
build_config 0.4.0 0.4.1
build_daemon 2.0.0
build_resolvers 1.0.6
build_runner_core 3.0.6
built_collection 4.2.2
built_value 6.7.0
charcode 1.1.2
code_builder 3.2.0
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.16.1
dart_style 1.2.9
fixnum 0.10.9
front_end 0.1.19 0.1.20
glob 1.1.7
graphs 0.2.0
html 0.14.0+2
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
kernel 0.3.19 0.3.20
logging 0.11.3+2
matcher 0.12.5
meta 1.1.7
mime 0.9.6+3
package_config 1.0.5
package_resolver 1.0.10
path 1.6.2
pedantic 1.8.0+1
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.4
quiver 2.0.3
shelf 0.7.5
shelf_web_socket 0.2.3
source_gen 0.9.4+3
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.19
string_scanner 1.0.4
term_glyph 1.1.0
timing 0.1.1+1
typed_data 1.1.6
watcher 0.9.7+12
web_socket_channel 1.0.14
yaml 2.1.16

Admin