flutter_channel_json 1.0.2 copy "flutter_channel_json: ^1.0.2" to clipboard
flutter_channel_json: ^1.0.2 copied to clipboard

It is used to standardize the data format of method channel data transmission, usually combined with fluent_ channel_ event_ Bus usage

flutter_channel_json #

It is used to standardize the data format of method channel data transmission, usually combined with fluent_ channel_ event_ Bus use.

Add dependency #

flutter pub add flutter_channel_json

How do you use it? #

Dart #

import 'package:flutter_channel_json/flutter_channel_json.dart';

Default initialization

const json = FlutterChannelJson(
  code: 300,
  message: 'message',
  success: false,
  data: 2,
);

Initialize according to dictionary

final json = FlutterChannelJson.fromJson({
  'code': 300,
  'message': 'message',
  'data': 2,
  'success': false,
});

Initialization based on JSON string

final json = FlutterChannelJson.fromJsonString(
  '{"code": 300, "message": "message", "data": 2, "success": false}',
);

Convert object to dictionary

final json = const FlutterChannelJson(
  code: 300,
  message: 'message',
  success: false,
  data: 2,
).toJson();

Convert object to string

final json = const FlutterChannelJson(
  code: 300,
  message: 'message',
  success: false,
  data: 2,
).toJsonString();

Initialization success type

final json = FlutterChannelJson.success(2);

Initialization failure type

final json = FlutterChannelJson.failure('message');

Swift #

Default initialization

let json = FlutterChannelJson(code: 300,
                              message: "message",
                              data: 2,
                              success: false)

Initialization success type

let json = FlutterChannelJson(success: 2)

Initialization failure type

let json = FlutterChannelJson(failure: "message", code: 300)

Initialize according to dictionary

let json = FlutterChannelJson<Int>(json: ["code": 300,
                                          "message": "message",
                                          "data": 2,
                                          "success": false])

Initialization based on JSON string

let json = try? FlutterChannelJson<Int>(jsonString: "{\"code\":300,\"message\":\"message\",\"data\":2,\"success\":false}")

Object to JSON string

let json = FlutterChannelJson(code: 300,
                              message: "message",
                              data: 2,
                              success: false)
let jsonString = json.toJsonString()

Object to dictionary

let json = FlutterChannelJson(code: 300,
                              message: "message",
                              data: 2,
                              success: false)
let jsonMap = json.toJson()

Kotlin #

Default initialization

val json = FlutterChannelJson(code = 300, message = "message", data = 2, success = false)

Initialization success type

val json = FlutterChannelJson(data = 2)

Initialization failure type

val  json = FlutterChannelJson<Int>(message = "message")

Initialization based on JSON string

val json = FlutterChannelJson(jsonString = "{\"code\":300,\"message\":\"message\",\"data\":2,\"success\":false}", Int::class.java)

Initialize according to dictionary

val map: Map<String,Any> = mapOf("code" to 300, "message" to "message", "data" to 2, "success" to false)
val json = FlutterChannelJson<Int>(json = map)

Object to JSON string

val json = FlutterChannelJson(code = 300, message = "message", data = 2, success = false).toJsonString()

Object to dictionary

val json = FlutterChannelJson(code = 300, message = "message", data = 2, success = false)
val map = json.toJson()
0
likes
120
pub points
0%
popularity

Publisher

unverified uploader

It is used to standardize the data format of method channel data transmission, usually combined with fluent_ channel_ event_ Bus usage

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_channel_json