Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. class CategoryModel {
  2. List<_Category> _Categories = [];
  3.  
  4. CategoryModel.fromJson(Map<String, dynamic> parsedJson) {
  5. print(parsedJson['Categories'].length);
  6. List<_Category> temp = [];
  7. for (int i = 0; i < parsedJson['Categories'].length; i++) {
  8. //_Category is the constructor of _Category Class line number 21
  9. _Category category = _Category(parsedJson['Categories'][i]);
  10. temp.add(category);
  11. }
  12. _Categories = temp;
  13. }
  14.  
  15. List<_Category> get categories => _Categories;
  16. }
  17.  
  18. class _Category {
  19. int _id;
  20.  
  21. String _name;
  22.  
  23. String _iconPath;
  24.  
  25. _Category(category) {
  26. _id = category['id'];
  27. _name = category['name'];
  28. _iconPath = category['iconPath'];
  29. }
  30.  
  31. int get id => _id;
  32.  
  33. String get name => _name;
  34.  
  35. String get iconPath => _iconPath;
  36. }
  37.  
  38. Future<CategoryModel> fetchCategoryList() async {
  39. final jsonCategory = await rootBundle.loadString("assets/CategoryList.json");
  40. final mapJsonCategory = Map.from(jsonDecode(jsonCategory));
  41.  
  42. return CategoryModel.fromJson(mapJsonCategory);
  43. }
  44.  
  45. {
  46. "Categories": [
  47. {
  48. "id": 1,
  49. "name": "Restruants",
  50. "iconPath": " "
  51. },
  52. {
  53. "id": 2,
  54. "name": "Car Rental",
  55. "iconPath": " "
  56. },
  57. {
  58. "id": 3,
  59. "name": "Furniture",
  60. "iconPath": " "
  61. },
  62. {
  63. "id": 4,
  64. "name": "cars",
  65. "iconPath": " "
  66. },
  67. {
  68. "id": 5,
  69. "name": "Maintenance",
  70. "iconPath": " "
  71. },
  72. {
  73. "id": 6,
  74. "name": "Education",
  75. "iconPath": " "
  76. },
  77. {
  78. "id": 7
  79. "name": "Finess",
  80. "iconPath": " "
  81. },
  82. {
  83. "id": 8,
  84. "name": "Electronics",
  85. "iconPath": " "
  86. },
  87. {
  88. "id": 9,
  89. "name": "Medical",
  90. "iconPath": " "
  91. },
  92. {
  93. "id": 10,
  94. "name": "Entirtainment",
  95. "iconPath": " "
  96. }
  97. ]
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement