ubiquitous-durian-3116
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<SubSection> subsections = []; | |
final graphQLQuery = { | |
'query': '''query { | |
getSubsections(courseId: 16, sectionId: 16) { | |
id | |
sectionId | |
subtopic | |
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']['getSubsections']; | |
print(arr); | |
arr.forEach((sub) => subsections | |
.add(SubSection(title: sub['subtopic'], | |
lessons: [], | |
subSectionId: sub['id']) | |
)); | |
print(subsections[0].title); | |
} | |
class SubSection { | |
String title; | |
int subSectionId; | |
List lessons; | |
SubSection( | |
{required this.title, required this.lessons, required this.subSectionId}); | |
} |