Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CategoryModel {
- List<_Category> _Categories = [];
- CategoryModel.fromJson(Map<String, dynamic> parsedJson) {
- print(parsedJson['Categories'].length);
- List<_Category> temp = [];
- for (int i = 0; i < parsedJson['Categories'].length; i++) {
- //_Category is the constructor of _Category Class line number 21
- _Category category = _Category(parsedJson['Categories'][i]);
- temp.add(category);
- }
- _Categories = temp;
- }
- List<_Category> get categories => _Categories;
- }
- class _Category {
- int _id;
- String _name;
- String _iconPath;
- _Category(category) {
- _id = category['id'];
- _name = category['name'];
- _iconPath = category['iconPath'];
- }
- int get id => _id;
- String get name => _name;
- String get iconPath => _iconPath;
- }
- Future<CategoryModel> fetchCategoryList() async {
- final jsonCategory = await rootBundle.loadString("assets/CategoryList.json");
- final mapJsonCategory = Map.from(jsonDecode(jsonCategory));
- return CategoryModel.fromJson(mapJsonCategory);
- }
- {
- "Categories": [
- {
- "id": 1,
- "name": "Restruants",
- "iconPath": " "
- },
- {
- "id": 2,
- "name": "Car Rental",
- "iconPath": " "
- },
- {
- "id": 3,
- "name": "Furniture",
- "iconPath": " "
- },
- {
- "id": 4,
- "name": "cars",
- "iconPath": " "
- },
- {
- "id": 5,
- "name": "Maintenance",
- "iconPath": " "
- },
- {
- "id": 6,
- "name": "Education",
- "iconPath": " "
- },
- {
- "id": 7
- "name": "Finess",
- "iconPath": " "
- },
- {
- "id": 8,
- "name": "Electronics",
- "iconPath": " "
- },
- {
- "id": 9,
- "name": "Medical",
- "iconPath": " "
- },
- {
- "id": 10,
- "name": "Entirtainment",
- "iconPath": " "
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement