-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from PEC-CSS/feat/add-new-tt
Feat/add new tt
- Loading branch information
Showing
10 changed files
with
434 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.