Created with <3 with dartpad.dev.
Created
October 10, 2022 09:39
-
-
Save Jerome-Jumah/9cb3ca48054576fb832d9c8b88beca3b to your computer and use it in GitHub Desktop.
queries
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:http/http.dart' as http; | |
void main() async{ | |
final List<Section> sections = []; | |
final graphQLQuery = { | |
'query': '''query GetSections { | |
getSections { | |
id | |
courseId | |
topic | |
orderNum | |
} | |
}''' | |
}; | |
final response = await http | |
.post(Uri.parse('https://7522-197-232-145-163.eu.ngrok.io'), | |
headers: {'Content-Type': 'application/json'}, | |
body: jsonEncode(graphQLQuery) | |
); | |
final result = jsonDecode(response.body); | |
final arr = result['data']['getSections']; | |
print(arr); | |
arr.forEach((section) => sections | |
.add(Section(title: section['topic'], | |
subsections: [], | |
sectionId: section['id']) | |
)); | |
print(sections[0].title); | |
} | |
class Section { | |
String title; | |
int sectionId; | |
List subsections; | |
Section( | |
{required this.title, | |
required this.subsections, | |
required this.sectionId}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment