Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Last active September 30, 2022 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quingsley/805f1ec71a186a06c5c4e677a39c5f50 to your computer and use it in GitHub Desktop.
Save Quingsley/805f1ec71a186a06c5c4e677a39c5f50 to your computer and use it in GitHub Desktop.
course-upload-logic
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}){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment