jsoninflater 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new45

JsonInflater #

详细介绍: #

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

如何使用 #

  1. 创建模型,添加注解JsonFlater以及mixin类。如:

    @JsonInflater()
    class TestNonGenerics with PartOfTestNonGenerics {
    
      String msg;
    
      TestNonGenerics(this.msg);
    
      @override
      String toString() {
        return 'TestNonGenerics{msg: $msg}';
      }
    }
    
    @JsonInflater()
    class TestGenerics1<K> with PartOfTestGenerics1 {
    
      String msg;
      K data;
    
      TestGenerics1(this.msg, this.data);
    
      @override
      String toString() {
        return 'TestGenerics1{msg: $msg, data: $data}';
      }
    }
    
    @JsonInflater()
    class TestGenerics2<K> with PartOfTestGenerics2 {
    
      String msg;
      K data;
    
      TestGenerics2(this.msg, this.data);
    
 @override
 String toString() {
   return 'TestGenerics2{msg: $msg, data: $data}';
 }

}


   > `mixin`类是代码生成的,格式是:PartOf${className}。功能是提供`toJson()`、`parse()`方法。
   
   创建一个Json工具类,添加`JsonGather`注解。

@JsonGather() class JsonUtil {

}

   > 一个项目中只能有一个`JsonGather`注解。
   
2. 运行命令,生成代码:

flutter packages pub run build_runner clean flutter packages pub run build_runner build


3. 使用:

   - `toJson`.

     ```dart
     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>`

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

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

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

     例子:

     ```dart
     var genericsModel1 = TestGenerics1<TestNonGenerics>("generics model 1", nonGenericsModel);
       var genericsModel1Parse = parse2<TestGenerics1<TestNonGenerics>, TestNonGenerics>(genericsModel1.toJson());
       print("$genericsModel1Parse, ${genericsModel1Parse.runtimeType}"); // -> TestGenerics1{msg: generics model 1, data: TestNonGenerics{msg: non generics}}, TestGenerics1<TestNonGenerics>
     ```

   - `PartOf${className}<T>.parse()`。本框架提供的另外一个将Map转换成模型的方法。

     ```dart
     var parseTest4 = PartOfJsonTest.parse(test.toJson());
     print("$parseTest4"); // -> JsonTest{msg: json test}
     ```

   - `parse<T>()` 与 `PartOf${className}<T>.parse()`的差别:前者支持泛型嵌套,后者不支持。

<br/>

0.0.1 #

  • TODO: Describe initial release.

example/README.md

jsoninflater_example #

Demonstrates how to use the jsoninflater plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  jsoninflater: ^0.1.1

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';
  
Version Uploaded Documentation Archive
0.1.1 Mar 15, 2019 Go to the documentation of jsoninflater 0.1.1 Download jsoninflater 0.1.1 archive
0.1.0 Mar 14, 2019 Go to the documentation of jsoninflater 0.1.0 Download jsoninflater 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

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 181 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 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
build_runner ^1.0.0 1.2.8
json_annotation ^2.0.0 2.0.0
json_serializable ^2.0.0 2.0.3
Transitive dependencies
analyzer 0.35.3
args 1.5.1
async 2.0.8
build 1.1.1
build_config 0.3.1+4
build_daemon 0.4.2
build_resolvers 1.0.3
build_runner_core 2.0.3
built_collection 4.1.0
built_value 6.3.2
charcode 1.1.2
code_builder 3.2.0
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.14.6
dart_style 1.2.4
fixnum 0.10.9
front_end 0.1.13
glob 1.1.7
graphs 0.2.0
html 0.13.4+1
http 0.12.0+1
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
kernel 0.3.13
logging 0.11.3+2
matcher 0.12.4
meta 1.1.7
mime 0.9.6+2
package_config 1.0.5
package_resolver 1.0.10
path 1.6.2
pedantic 1.5.0
plugin 0.2.0+3
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.4
quiver 2.0.1
shelf 0.7.4
shelf_web_socket 0.2.2+4
source_gen 0.9.4+1
source_span 1.5.5
stack_trace 1.9.3
stream_channel 1.6.8
stream_transform 0.0.16+1
string_scanner 1.0.4
term_glyph 1.1.0
timing 0.1.1+1
typed_data 1.1.6
utf 0.9.0+5
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15