Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
82
lib/models/quiz_model.dart
Normal file
82
lib/models/quiz_model.dart
Normal file
@ -0,0 +1,82 @@
|
||||
// To parse this JSON data, do
|
||||
//
|
||||
// final quizModel = quizModelFromJson(jsonString);
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
QuizModel quizModelFromJson(String str) => QuizModel.fromJson(json.decode(str));
|
||||
|
||||
String quizModelToJson(QuizModel data) => json.encode(data.toJson());
|
||||
|
||||
class QuizModel {
|
||||
int status;
|
||||
bool error;
|
||||
int total;
|
||||
List<Datum> data;
|
||||
|
||||
QuizModel({
|
||||
required this.status,
|
||||
required this.error,
|
||||
required this.total,
|
||||
required this.data,
|
||||
});
|
||||
|
||||
factory QuizModel.fromJson(Map<String, dynamic> json) => QuizModel(
|
||||
status: json["status"],
|
||||
error: json["error"],
|
||||
total: json["total"],
|
||||
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"status": status,
|
||||
"error": error,
|
||||
"total": total,
|
||||
"data": List<dynamic>.from(data.map((x) => x.toJson())),
|
||||
};
|
||||
}
|
||||
|
||||
class Datum {
|
||||
String id;
|
||||
String quizId;
|
||||
String title;
|
||||
String type;
|
||||
String numberOption;
|
||||
List<String> options;
|
||||
List<String> correctAnswers;
|
||||
String order;
|
||||
|
||||
Datum({
|
||||
required this.id,
|
||||
required this.quizId,
|
||||
required this.title,
|
||||
required this.type,
|
||||
required this.numberOption,
|
||||
required this.options,
|
||||
required this.correctAnswers,
|
||||
required this.order,
|
||||
});
|
||||
|
||||
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
|
||||
id: json["id"],
|
||||
quizId: json["quiz_id"],
|
||||
title: json["title"],
|
||||
type: json["type"],
|
||||
numberOption: json["number_option"],
|
||||
options: List<String>.from(json["options"].map((x) => x)),
|
||||
correctAnswers:
|
||||
List<String>.from(json["correct_answers"].map((x) => x)),
|
||||
order: json["order"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"quiz_id": quizId,
|
||||
"title": title,
|
||||
"type": type,
|
||||
"number_option": numberOption,
|
||||
"options": List<dynamic>.from(options.map((x) => x)),
|
||||
"correct_answers": List<dynamic>.from(correctAnswers.map((x) => x)),
|
||||
"order": order,
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user