jsoninflater 0.2.0

  • Readme
  • Changelog
  • Installing
  • 42

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]
1
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
59
Overall:
Weighted score of the above. [more]
42
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

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 of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:jsoninflater/jsonGather.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

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.

Package is getting outdated. (-0.82 points)

The package was last published 52 weeks ago.

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.9.0 1.10.0
json_annotation ^2.0.0 2.3.0 3.0.1
json_serializable ^2.0.0 2.3.0 3.3.0
Transitive dependencies
analyzer 0.36.4 0.39.12
args 1.6.0
async 2.4.2
build 1.2.2 1.3.0
build_config 0.4.2
build_daemon 2.1.4
build_resolvers 1.2.1 1.3.10
build_runner_core 5.1.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.3.0
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.2.9 1.3.6
fixnum 0.10.11
front_end 0.1.19 0.1.29
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http 0.12.1
http_multi_server 2.2.0
http_parser 3.1.4
io 0.3.4
js 0.6.2
kernel 0.3.19 0.3.29
logging 0.11.4
matcher 0.12.8
meta 1.2.1
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
package_resolver 1.0.10
path 1.7.0
pedantic 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
source_gen 0.9.4+4 0.9.5
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.2.0
watcher 0.9.7+15
web_socket_channel 1.1.0
yaml 2.2.1