Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- class DesignItem {
- final String name;
- final String id;
- final Map meta;
- DesignItem(this.name, {String id, this.meta = const {}}) : id = id ?? name;
- factory DesignItem.fromString(String fileSrc) {
- final fileData = json.decode(fileSrc) as Map;
- return DesignItem(fileData['name'], id: fileData['id'], meta: fileData['meta']);
- }
- /// Makes the class serializable
- @override
- String toString() => '{id: $id, name: $name, meta: $meta}';
- }
- class Design {
- final String name;
- final String id;
- final List<DesignItem> items;
- final Map meta;
- Design(this.name, this.items, {String id, this.meta = const {}}) : id = id ?? name;
- factory Design.fromString(String fileSrc) {
- final fileData = json.decode(fileSrc) as Map;
- final serializedItems = (fileData['items'] as List).cast<Map>();
- return Design(fileData['name'],
- serializedItems.map((serializedItemData) => DesignItem.fromString(json.encode(serializedItemData))).toList(),
- id: fileData['id'],
- meta: fileData['meta']);
- }
- /// Makes the class serializable
- @override
- String toString() => '{id: $id, name: $name, items: $items, meta: $meta}';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement