Skip to content

michael-wang/mikeway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

While develop with dart/Flutter, I developed certain ways of doing things. I collect them in this package and publish it for anyone who may need it.

Features

  • Enhancement for dart:convert package.

Getting started

Adding package to pubspec.yaml:

dependencies:
    mikeway ^0.0.1

Import the package in the source file and you're up to go:

import 'package:mikeway/mikeway.dart';

Usage

Say you have a Person class to encode and decode:

import 'package:mikeway/mikeway.dart';

class Person implements JsonEncodable {
  final String name;
  final int age;

  Person(this.name, this.age);

  @override
  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'age': age,
    };
  }

  factory Person.fromJson(Map<String, dynamic> map) {
    return Person(map['name'], map['age']);
  }
}

Here is how you encode from Person to String, and decode from String to Person object:

print(jsonEncode(Person('mike', 20), indenx: '  '));
// {
//   "name": "mike",
//   "age": 20
// }

final user = jsonDecode('{"name": "mike", "age": 20}', Person.fromJson);
print(user.runtimeType);
// Person
print(user.toJson());
// {name: mike, age: 20}

Roadmap

About

My way of developing dart/flutter project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages