course-upload-logic
Created with <3 with dartpad.dev.
Created with <3 with dartpad.dev.
import 'package:flutter/material.dart'; | |
void main() { | |
for (int i = 0; i < 5; i++) { | |
print('hello ${i + 1}'); | |
} | |
final course = Course(creatorId: '', courseTitle: '', courseDescription: '', | |
courseSection: [] | |
); | |
course.courseSection.add( | |
Section(title: 'sec1', subsections: []) | |
); | |
var section = course.courseSection.firstWhere((section) => | |
section.title == 'sec1' | |
); | |
section.subsections.add( | |
SubSection( | |
title: 'sub1', lessons: [] | |
)); | |
var subsection = section.subsections.firstWhere((subsection) => subsection.title == 'sub1'); | |
subsection.lessons.add( | |
Lessons(title: '', objective: '', video: '') | |
); | |
} | |
class Course { | |
String courseId; | |
String creatorId; | |
String courseTitle; | |
String courseDescription; | |
String classId; | |
List <Section> courseSection; | |
Course({ | |
required this.creatorId, | |
this.courseId = '', | |
required this.courseTitle, | |
required this.courseDescription, | |
this.classId = '', | |
required this.courseSection, | |
}); | |
} | |
class Section { | |
String title; | |
String sectionId; | |
List<SubSection> subsections; | |
Section({required this.title, required this.subsections, this.sectionId = ''}); | |
} | |
class SubSection { | |
String title; | |
String subSectionId; | |
List<Lessons> lessons; | |
SubSection({required this.title, required this.lessons, this.subSectionId = ''}); | |
} | |
class Lessons { | |
String title; | |
String lessonId; | |
String objective; | |
String text; | |
dynamic video; | |
dynamic image; | |
Lessons({required this.title, required this.objective, required this.video, this.image, this.text = '', this.lessonId = ''}); | |
} | |
// Submit methods | |
//need to use material.dart | |
var course; | |
class SubmitCourseDetails { | |
static bool validate(GlobalKey<FormState> formKey){ | |
bool isValid = formKey.currentState!.validate(); | |
if(isValid) { | |
formKey.currentState!.save(); | |
return isValid; | |
} else { | |
return isValid; | |
} | |
} | |
static submitCourse({courseID = null, creatorId , classId, courseTitle, courseDescription, formKey}){ | |
bool isValid = SubmitCourseDetails.validate(formKey); | |
if(isValid){ | |
course = Course(creatorId: creatorId, courseTitle: courseTitle,courseDescription: courseDescription, courseSection: [] ); | |
} | |
} | |
static submitSection({sectionID = null, classId, courseTitle, sectionTitle, formKey}){ | |
bool isValid = SubmitCourseDetails.validate(formKey); | |
if(isValid){ | |
course.courseSection.add( | |
Section(title: sectionTitle, subsections: []) | |
); | |
} | |
} | |
static submitsubSection({subsectionId = null , subsectionTitle, sectionTitle, formKey} ){ | |
bool isValid = SubmitCourseDetails.validate(formKey); | |
if(isValid){ | |
var section = course.courseSection.firstWhere((section) => | |
section.title == sectionTitle | |
); | |
section.subsections.add( | |
SubSection( | |
title: subsectionTitle, lessons: [] | |
)); | |
} | |
} | |
static submitLessonDetails({lessonId = null, subsectionTitle, lessonTitle, lessonDescription, videoUrl}){ | |
} | |
} |