SHARE
TWEET

Untitled

a guest Oct 14th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'dart:convert';
  2.  
  3. class DesignItem {
  4.   final String name;
  5.   final String id;
  6.   final Map meta;
  7.  
  8.   DesignItem(this.name, {String id, this.meta = const {}}) : id = id ?? name;
  9.  
  10.   factory DesignItem.fromString(String fileSrc) {
  11.     final fileData = json.decode(fileSrc) as Map;
  12.  
  13.     return DesignItem(fileData['name'], id: fileData['id'], meta: fileData['meta']);
  14.   }
  15.  
  16.   /// Makes the class serializable
  17.   @override
  18.   String toString() => '{id: $id, name: $name, meta: $meta}';
  19. }
  20.  
  21. class Design {
  22.   final String name;
  23.   final String id;
  24.   final List<DesignItem> items;
  25.   final Map meta;
  26.  
  27.   Design(this.name, this.items, {String id, this.meta = const {}}) : id = id ?? name;
  28.  
  29.   factory Design.fromString(String fileSrc) {
  30.     final fileData = json.decode(fileSrc) as Map;
  31.     final serializedItems = (fileData['items'] as List).cast<Map>();
  32.  
  33.     return Design(fileData['name'],
  34.         serializedItems.map((serializedItemData) => DesignItem.fromString(json.encode(serializedItemData))).toList(),
  35.         id: fileData['id'],
  36.         meta: fileData['meta']);
  37.   }
  38.  
  39.   /// Makes the class serializable
  40.   @override
  41.   String toString() => '{id: $id, name: $name, items: $items, meta: $meta}';
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top