queries
Created with <3 with dartpad.dev.
Created with <3 with dartpad.dev.
import 'dart:convert'; | |
import 'package:http/http.dart' as http; | |
void main() async{ | |
final List<Section> sections = []; | |
final graphQLQuery = { | |
'query': '''query { | |
getSections(courseId: 16) { | |
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); | |
} | |
class Section { | |
String title; | |
int sectionId; | |
List subsections; | |
Section( | |
{required this.title, | |
required this.subsections, | |
required this.sectionId}); | |
} |