Created
March 20, 2023 06:05
-
-
Save mhassanist/421181f70ffdedf35c5f4a3147a33abc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:corereservations/models/facility.dart'; | |
import 'package:http/http.dart' as http; //alias | |
class FacilitiesApi { | |
getFacilities() async { | |
var response = await http.get(Uri.parse( | |
'https://gist.githubusercontent.com/mhassanist/38201f235f6c1b7a0b4f89effb89a399/raw/96ae3599141d35af90337b9d24b8550e36ed1a87/facilities.json')); | |
var responseJson = jsonDecode(response.body); | |
List<Facility> facilities = []; | |
for (var item in responseJson["data"]) { | |
Facility facility = Facility.fromJson(item); | |
facilities.add(facility); | |
} | |
print(facilities); | |
return facilities; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment