Task: Add toJson interfaces and export

This commit is contained in:
Sambo Chea 2021-06-02 17:16:54 +07:00
parent 19ddc8114c
commit 942095bbdd
3 changed files with 11 additions and 3 deletions

View File

@ -1,3 +1,4 @@
import 'package:cubetiq/src/json.dart';
import 'package:cubetiq/xlog.dart'; import 'package:cubetiq/xlog.dart';
void main(List<String> args) { void main(List<String> args) {
@ -15,17 +16,18 @@ void main(List<String> args) {
XLog.warning(null); XLog.warning(null);
var json = Person(1, 'Sambo'); var person = Person(1, 'Sambo');
XLog.warning(json, [null, null]); XLog.warning(person, [null, null]);
} }
class Person { class Person implements ToJson {
final id; final id;
final name; final name;
Person(this.id, this.name); Person(this.id, this.name);
@override
Map toJson() => { Map toJson() => {
'id': id, 'id': id,
'name': name, 'name': name,

3
lib/interfaces.dart Normal file
View File

@ -0,0 +1,3 @@
library interfaces;
export 'src/json.dart';

3
lib/src/json.dart Normal file
View File

@ -0,0 +1,3 @@
abstract class ToJson {
Map toJson();
}