From 942095bbdd2fff3838ff0bd0ca66bb3c37d8c8ea Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Wed, 2 Jun 2021 17:16:54 +0700 Subject: [PATCH] Task: Add toJson interfaces and export --- example/cubetiq_xlog_example.dart | 8 +++++--- lib/interfaces.dart | 3 +++ lib/src/json.dart | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 lib/interfaces.dart create mode 100644 lib/src/json.dart diff --git a/example/cubetiq_xlog_example.dart b/example/cubetiq_xlog_example.dart index f898ea5..5bfa9b6 100644 --- a/example/cubetiq_xlog_example.dart +++ b/example/cubetiq_xlog_example.dart @@ -1,3 +1,4 @@ +import 'package:cubetiq/src/json.dart'; import 'package:cubetiq/xlog.dart'; void main(List args) { @@ -15,17 +16,18 @@ void main(List args) { 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 name; Person(this.id, this.name); + @override Map toJson() => { 'id': id, 'name': name, diff --git a/lib/interfaces.dart b/lib/interfaces.dart new file mode 100644 index 0000000..bdfec90 --- /dev/null +++ b/lib/interfaces.dart @@ -0,0 +1,3 @@ +library interfaces; + +export 'src/json.dart'; diff --git a/lib/src/json.dart b/lib/src/json.dart new file mode 100644 index 0000000..7c1530d --- /dev/null +++ b/lib/src/json.dart @@ -0,0 +1,3 @@ +abstract class ToJson { + Map toJson(); +}