import 'dart:convert';
import 'dart:io';
class Employee {
String name;
int age;
Employee(this.name, this.age);
Map<String, dynamic> toMap() {
return <String, dynamic>{
'name': name,
'age': age,
};
}
String toJson() => json.encode(toMap());
}
class Department {
String name;
Employee leader;
Department(this.name, this.leader);
Map<String, dynamic> toMap() {
return <String, dynamic>{
'name': name,
'leader': leader.toMap(),
};
}
String toJson() => json.encode(toMap());
}
void main() {
Department hongGilDong = Department('총무부 리더', Employee('홍길동', 41));
File companyFile = File('lib/12_11/company.txt');
companyFile.writeAsStringSync(hongGilDong.toJson());
print(companyFile.readAsStringSync());
}