Advertisement
abimulya_

Untitled

Dec 30th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.63 KB | None | 0 0
  1. import 'package:freezed_annotation/freezed_annotation.dart';
  2.  
  3. part 'health_pregnancy_model.freezed.dart';
  4. part 'health_pregnancy_model.g.dart';
  5.  
  6. @freezed
  7. class HealthPregnancyModel with _$HealthPregnancyModel {
  8.   factory HealthPregnancyModel({
  9.     required final Quiz quiz,
  10.     required final TopicPage topicPage,
  11.   }) = _HealthPregnancyModel;
  12.  
  13.   factory HealthPregnancyModel.fromJson(Map<String, dynamic> json) =>
  14.       _$HealthPregnancyModelFromJson(json);
  15. }
  16.  
  17. @freezed
  18. class TopicPage with _$TopicPage {
  19.   factory TopicPage({
  20.     required final String headerText,
  21.     required final String reference1,
  22.     required final String reference2,
  23.     required final String reference3,
  24.     required final String subTopic1Title,
  25.     required final String subTopic2Title,
  26.   }) = _TopicPage;
  27.  
  28.   factory TopicPage.fromJson(Map<String, dynamic> json) =>
  29.       _$TopicPageFromJson(json);
  30. }
  31.  
  32. @freezed
  33. class Quiz with _$Quiz {
  34.   factory Quiz({
  35.     @JsonKey(fromJson: Quiz.quizFromJson, toJson: Quiz.quizToJson)
  36.     required final List<QuizData> quiz,
  37.   }) = _Quiz;
  38.  
  39.   factory Quiz.fromJson(Map<String, dynamic> json) => _$QuizFromJson(json);
  40.  
  41.   static quizFromJson(List<dynamic> listOfItem) => listOfItem.isEmpty
  42.       ? []
  43.       : listOfItem.map((item) => QuizData.fromJson(item)).toList();
  44.  
  45.   static quizToJson(List<QuizData?> items) => items.isEmpty
  46.       ? []
  47.       : items
  48.           .map((item) => _$$QuizDataImplToJson(item as _$QuizDataImpl))
  49.           .toList();
  50. }
  51.  
  52. @freezed
  53. class QuizData with _$QuizData {
  54.   factory QuizData({
  55.     required final Answer answer,
  56.     required final String question,
  57.   }) = _QuizData;
  58.  
  59.   factory QuizData.fromJson(Map<String, dynamic> json) =>
  60.       _$QuizDataFromJson(json);
  61. }
  62.  
  63. @freezed
  64. class Answer with _$Answer {
  65.   factory Answer({
  66.     @JsonKey(
  67.       fromJson: Answer.answerFromJson,
  68.       toJson: Answer.answerToJson,
  69.     )
  70.     required final List<AnswerData> answer,
  71.   }) = _Answer;
  72.  
  73.   factory Answer.fromJson(Map<String, dynamic> json) => _$AnswerFromJson(json);
  74.  
  75.   static answerFromJson(List<dynamic> listOfItem) => listOfItem.isEmpty
  76.       ? []
  77.       : listOfItem.map((item) => AnswerData.fromJson(item)).toList();
  78.  
  79.   static answerToJson(List<AnswerData?> items) => items.isEmpty
  80.       ? []
  81.       : items
  82.           .map((item) => _$$AnswerDataImplToJson(item as _$AnswerDataImpl))
  83.           .toList();
  84. }
  85.  
  86. @freezed
  87. class AnswerData with _$AnswerData {
  88.   factory AnswerData({
  89.     required final bool rightStatus,
  90.     required final String text,
  91.   }) = _AnswerData;
  92.  
  93.   factory AnswerData.fromJson(Map<String, dynamic> json) =>
  94.       _$AnswerDataFromJson(json);
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement