xmapper 1.0.4 copy "xmapper: ^1.0.4" to clipboard
xmapper: ^1.0.4 copied to clipboard

SDKDart
outdated

A starting point for Dart libraries or applications.

example/xmapper_example.dart

import 'dart:convert';

import 'package:xmapper/xmapper.dart';

class LoginForm {
  late String pubKey;
  late String name;
  late String avatar;
  late String invitationCode;
  late int canSearch;
  LoginForm(
      {required this.pubKey,
      required this.name,
      required this.avatar,
      this.invitationCode = '',
      this.canSearch = 0});
  @override
  String toString() => 'User($pubKey name:$name, avatar:$avatar)';
}

class UserInfo {
  late String userId;
  late String name;
  late String avatar;
  late String number;
  late int canSearch;
  UserInfo(
      {required this.userId,
      required this.name,
      required this.avatar,
      required this.number,
      required this.canSearch});
}

void main() {
  final json = '''{
	"pub_key": "03e4716fb1db615cfd5d776e25d6e7e074fbe201c04b5b4aee9922d3c1cec123bc",
	"name": "Alice",
	"avatar": "Girl",
	"can_search": 0
}''';
  final obj = Mapper<LoginForm>().object(jsonDecode(json));
  print('obj: $obj');
  final resp = UserInfo(
      userId: obj!.pubKey,
      name: obj.name,
      avatar: obj.avatar,
      number: '001',
      canSearch: 0);
  final map = Mapper<UserInfo>().toMap(resp);
  print(map);
}
0
likes
135
pub points
0%
popularity

Publisher

unverified uploader

A starting point for Dart libraries or applications.

Documentation

API reference

License

GPL-3.0 (license)

More

Packages that depend on xmapper