Skip to content

Commit

Permalink
Merge pull request #13 from PEC-CSS/feat/add-new-tt
Browse files Browse the repository at this point in the history
Feat/add new tt
  • Loading branch information
notSanil committed Apr 23, 2022
2 parents 4ff5b58 + b9f9b54 commit f27151b
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 99 deletions.
16 changes: 9 additions & 7 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import '../model/subject_model.dart';
import '../model/days.dart';
import '../model/task_model.dart';
import 'package:flutter/material.dart';


class Database{
static List<Subject> get(Days day){
List<Task> dummyTasks = [];
List<Subject> subjects = [];

subjects.add(Subject(code: "T01", name: "Test01",
startTime: DateTime(2022, 1, 21, 11, 50), duration: Duration(hours: 1), tasks: dummyTasks
subjects.add(Subject(name: "Test01", color: Colors.blue,
startTime: DateTime(2022, 1, 21, 11, 50), duration: Duration(hours: 1),
));

dummyTasks.add(Task(title: "Test work", deadline: DateTime.now(), description: "Hello", id: "10"));
dummyTasks.add(Task(title: "TestWork2", deadline: DateTime(2023), id: "11"));
subjects.add(Subject( name: "Test02", code: "T02",
startTime: DateTime(2022, 1, 21, 12, 50), duration: Duration(hours: 1), tasks: dummyTasks
subjects.add(Subject( name: "Test02", color: Colors.red,
startTime: DateTime(2022, 1, 21, 12, 50), duration: Duration(hours: 1),
description: "This is sample data about the subject.\nNew line",
));

return subjects;
Expand All @@ -30,4 +29,7 @@ class Database{

return tasks;
}
static addNewTimeTable(List<List<Subject>> data) {

}
}
2 changes: 1 addition & 1 deletion lib/home/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Day extends StatelessWidget {
List<Subject> subjects = Database.get(this.day);
List<SubjectCard> cards = [];
for (Subject subject in subjects){
cards.add(SubjectCard(subject: subject, color: Colors.red,));
cards.add(SubjectCard(subject: subject));
}
return cards;
}
Expand Down
52 changes: 45 additions & 7 deletions lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import 'package:flutter/material.dart';
import 'day.dart';
import '../model/days.dart';
import '../widgets/tasks_button.dart';
import '../new_time_table/new_time_table_page.dart';

class Home extends StatelessWidget {
final String title;
final List<Widget> tabs = <Widget>[
Tab(text: "Monday",),
Tab(text: "Tuesday",),
Tab(text: "Wednesday",),
Tab(text: "Thursday",),
Tab(text: "Friday",),
Tab(text: "Saturday",),
Tab(text: "Sunday",)
Tab(text: Days.Monday.name,),
Tab(text: Days.Tuesday.name,),
Tab(text: Days.Wednesday.name,),
Tab(text: Days.Thursday.name,),
Tab(text: Days.Friday.name,),
Tab(text: Days.Saturday.name,),
Tab(text: Days.Sunday.name,)
];

Home({Key? key, required this.title}) : super(key: key);
Expand All @@ -31,6 +32,7 @@ class Home extends StatelessWidget {
isScrollable: true,
),
),
drawer: HomeDrawer(),
body: TabBarView(
children: [
Day(day: Days.Monday),
Expand All @@ -48,3 +50,39 @@ class Home extends StatelessWidget {
);
}
}

class HomeDrawer extends StatelessWidget {
const HomeDrawer({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
child: Text("Welcome back user"),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: const Text(
"Create a new timetable",
style: TextStyle(
fontSize: 18.0
),
),
onTap: (){
Navigator.push(context, MaterialPageRoute(
builder: (context) => NewTimeTablePage()
));
},
)
],
),
);
}
}
11 changes: 5 additions & 6 deletions lib/model/subject_model.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'task_model.dart';
import 'package:flutter/material.dart';

class Subject{
String name;
String code;
DateTime startTime;
Duration duration;
Color color;
String description;

List<Task> tasks;

Subject({required this.name, required this.code,
required this.startTime, required this.duration, required this.tasks});
Subject({required this.name, required this.color, this.description="",
required this.startTime, required this.duration});
}
229 changes: 229 additions & 0 deletions lib/new_time_table/new_subject_card_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import 'package:flutter/material.dart';
import 'package:time_table_app/model/subject_model.dart';
import 'package:flex_color_picker/flex_color_picker.dart';

class NewSubject extends StatefulWidget {
NewSubject(this.day, this.data, {Key? key}) : super(key: key);
final int day;
final List<List<Subject>> data;

@override
State<NewSubject> createState() => _NewSubjectState();
}

class _NewSubjectState extends State<NewSubject> {
DateTime startTime = DateTime.now();
DateTime endTime = DateTime.now().add(Duration(hours: 1));

final TextEditingController titleController = TextEditingController();
final TextEditingController descriptionController = TextEditingController();

Color currentColor = Colors.red;

void changeStartTime(TimeOfDay newTime) {
DateTime current = DateTime.now();
startTime = DateTime(
current.year, current.month, current.day, newTime.hour, newTime.minute);
print("called");
}

void changeEndTime(TimeOfDay newTime) {
DateTime current = DateTime.now();
endTime = DateTime(
current.year, current.month, current.day, newTime.hour, newTime.minute);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: TextField(
controller: titleController,
decoration: InputDecoration(
hintText: "Title",
border: InputBorder.none,
hintStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0),
),
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0),
),
),
body: ListView(
padding: EdgeInsets.all(8.0),
children: [
Container(
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.circular(8.0),
),
padding: EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TimeButton(
TimeOfDay.fromDateTime(startTime).replacing(minute: 0),
label: "Start: ",
callback: changeStartTime),
TimeButton(
TimeOfDay.fromDateTime(endTime).replacing(minute: 0),
label: "End: ",
callback: changeEndTime,
),
],
),
),
ElevatedButton(
onPressed: () async {
final colorBeforeDialog = currentColor;

if (!await ColorPicker(
color: currentColor,
onColorChanged: (Color col) {
setState(() {
currentColor = col;
});
},
pickersEnabled: const <ColorPickerType, bool>{
ColorPickerType.both: false,
ColorPickerType.primary: true,
ColorPickerType.accent: false,
ColorPickerType.bw: false,
ColorPickerType.custom: false,
ColorPickerType.wheel: false,
},
width: 44,
height: 44,
borderRadius: 22,
heading: Text(
'Select color',
style: Theme.of(context).textTheme.headline6,
),
subheading: Text(
'Select color shade',
style: Theme.of(context).textTheme.subtitle1,
),
).showPickerDialog(context)) {
setState(() {
currentColor = colorBeforeDialog;
});
}
},
child: Text("Color"),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(currentColor)),
),
SizedBox(
height: 10,
),
TextField(
controller: descriptionController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "Description",
),
textCapitalization: TextCapitalization.sentences,
minLines: 6,
maxLines: null,
),
ElevatedButton(
child: Text("Add"),
onPressed: () {
String title = titleController.text;
if (title.isEmpty) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text("Enter a title."),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("OK"))
],
);
});
} else {
Duration duration = endTime.difference(startTime);
String desc = descriptionController.text.trim();
Subject newSubject = Subject(
name: title,
description: desc,
startTime: startTime,
duration: duration,
color: currentColor);

this.widget.data[this.widget.day].add(newSubject);
Navigator.pop(context);
}
},
)
],
),
);
}
}

class TimeButton extends StatefulWidget {
TimeButton(this.time, {Key? key, required this.label, required this.callback})
: super(key: key);

final String label;
final TimeOfDay time;
final void Function(TimeOfDay) callback;

@override
State<TimeButton> createState() => _TimeButtonState();
}

class _TimeButtonState extends State<TimeButton> {
TimeOfDay time = TimeOfDay.now();
void setNewTime(BuildContext context) async {
TimeOfDay? newTime = await showTimePicker(
context: context,
initialTime: time.replacing(minute: 0),
);
setState(() {
if (newTime != null) {
time = newTime;
widget.callback(time);
}
});
}

@override
void initState() {
super.initState();
time = widget.time;
widget.callback(time);
}

@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
widget.label,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
TextButton(
onPressed: () => setNewTime(context),
child: Text(
time.hour.toString().padLeft(2, '0') +
":" +
time.minute.toString().padLeft(2, '0'),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black54),
),
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
alignment: Alignment.bottomCenter),
),
],
);
}
}

0 comments on commit f27151b

Please sign in to comment.