diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c819ee2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "DayToDay", + "request": "launch", + "type": "dart" + }, + { + "name": "DayToDay (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "DayToDay (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 1253e65..9062d2c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -45,7 +45,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.day_to_day" - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/assets/icons/dayToDayLogo.jpg b/assets/icons/dayToDayLogo.jpg new file mode 100644 index 0000000..f8e110c Binary files /dev/null and b/assets/icons/dayToDayLogo.jpg differ diff --git a/assets/icons/dtdLogo1.png b/assets/icons/dtdLogo1.png new file mode 100644 index 0000000..e6d228b Binary files /dev/null and b/assets/icons/dtdLogo1.png differ diff --git a/assets/icons/dtdLogo2.jpg b/assets/icons/dtdLogo2.jpg new file mode 100644 index 0000000..637feb7 Binary files /dev/null and b/assets/icons/dtdLogo2.jpg differ diff --git a/lib/assignments.dart b/lib/assignments.dart new file mode 100644 index 0000000..f602f91 --- /dev/null +++ b/lib/assignments.dart @@ -0,0 +1,85 @@ +import 'package:flutter/material.dart'; +import 'event_form.dart'; +import 'globals.dart' as globals; +import 'events.dart'; + +class AssignmentsWidget extends StatefulWidget { + List hw = []; + AssignmentsWidget({Key? key, required this.stream}) : super(key: key); + final Stream stream; + + @override + State createState() => AssignmentsState(); +} + +class AssignmentsState extends State { + int count = 2; + + @override + void initState() { + + widget.stream.listen((event) { + setState(() { + + }); + }); + super.initState(); + } + + @override + Widget build(BuildContext context) { + widget.hw = []; + globals.eventsList.forEach((key, value) { + for (int i = 0; i < value.length; i++) { + if (value[i].type.contains("assign")) { + widget.hw.add(value[i]); + } + } + }); + return Scaffold( + appBar: AppBar( + title: const Center(child: Text("Assignments List")), + backgroundColor: const Color.fromARGB(255, 255, 82, 82), + ), + body: ListView.builder( + itemCount: widget.hw.length, + itemBuilder: (BuildContext context, int index) { + return Card( + child: CheckboxListTile( + dense: true, + activeColor: Colors.red[400], + controlAffinity: ListTileControlAffinity.leading, + value: false, + onChanged: (value) { + setState(() { + widget.hw.removeAt(index); + }); + }, + title: Text( + widget.hw[index].title, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Color.fromARGB(255, 12, 12, 12)), + ))); + }, + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + Navigator.of(context).push(MaterialPageRoute(builder: (context) { + return EventForm(); + })); + }); + setState(() {}); + }, + child: const Icon( + Icons.add, + size: 45, + color: Colors.white, + ), + backgroundColor: Colors.blueGrey, + ), + ); + } +} diff --git a/lib/calendar.dart b/lib/calendar.dart index cc72d14..3bc1698 100644 --- a/lib/calendar.dart +++ b/lib/calendar.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:day_to_day/inherited.dart'; import 'package:day_to_day/months.dart'; import 'package:flutter/material.dart'; +import 'event_form.dart'; import 'events.dart'; import 'globals.dart' as globals; import 'package:firebase_database/firebase_database.dart'; @@ -10,6 +11,7 @@ class CalendarWidget extends StatefulWidget { const CalendarWidget({Key? key, required this.stream}) : super(key: key); final Stream stream; + @override State createState() => CalendarState(); } @@ -22,6 +24,8 @@ class CalendarState extends State { int clickedPosition = -1; List dayClicked = []; Map span = {}; + int pag = 0; + List deleteSearch = []; @override void initState() { @@ -53,312 +57,341 @@ class CalendarState extends State { bool darkMode = systemColor == Brightness.dark; return InheritedState( - child: Column( - children: [ - Expanded( - //Builds separate page for each month of every year since 1980 - child: PageView.builder( - controller: pageController, - scrollDirection: Axis.vertical, - itemBuilder: (BuildContext context, int pages) { - int temporaryM = pages; + child: Scaffold( + floatingActionButton: FloatingActionButton( + onPressed: () => onAddEventButtonPressed(), + child: const Icon( + Icons.add, + size: 45, + color: Colors.white, + ), + backgroundColor: Colors.blueGrey, + ), + body: Column( + children: [ + Expanded( + //Builds separate page for each month of every year since 1980 + child: PageView.builder( + controller: pageController, + scrollDirection: Axis.vertical, + itemBuilder: (BuildContext context, int pages) { + int temporaryM = pages; + pag = pages; - if (clickedPosition == -1) { - clickedPosition = getCurrentDay(); - if (globals.eventsList[getCurrentDay().toString() + - getCurrentMonth().toString() + - getCurrentYear().toString()] != - null) { - globals.eventsList[getCurrentDay().toString() + + if (clickedPosition == -1) { + Widget firstLine; + Widget secondLine; + clickedPosition = getCurrentDay(); + if (globals.eventsList[getCurrentDay().toString() + getCurrentMonth().toString() + - getCurrentYear().toString()] - ?.forEach((element) { - dayClicked.add(Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - padding: const EdgeInsets.only(right: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 15, - width: 2, - ), - const Padding(padding: EdgeInsets.only(right: 10)), - Text( - element.title, - style: const TextStyle( - fontWeight: FontWeight.bold, fontSize: 20), - ), - ], - )); - String timeF = TimeOfDay( - hour: element.from.hour, - minute: element.from.minute) - .format(context); - String timeT = TimeOfDay( - hour: element.to.hour, minute: element.to.minute) - .format(context); - String repeatingString; + getCurrentYear().toString()] != + null) { + globals.eventsList[getCurrentDay().toString() + + getCurrentMonth().toString() + + getCurrentYear().toString()] + ?.forEach((element) { + firstLine = Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + padding: const EdgeInsets.only(right: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 15, + width: 2, + ), + const Padding(padding: EdgeInsets.only(right: 10)), + Text( + element.title, + style: const TextStyle( + fontWeight: FontWeight.bold, fontSize: 20), + ), + ], + ); + String timeF = TimeOfDay( + hour: element.from.hour, + minute: element.from.minute) + .format(context); + String timeT = TimeOfDay( + hour: element.to.hour, + minute: element.to.minute) + .format(context); + String repeatingString; - if (element.from.day == element.to.day && - element.from.month == element.to.month && - element.from.year == element.to.year) { - dayClicked.add(Center( - child: Padding( - padding: const EdgeInsets.only(bottom: 20), - child: Text(timeF + " - " + timeT), - ), - )); - } else if (element.from.year == element.to.year) { - dayClicked.add(Center( - child: Padding( - padding: const EdgeInsets.only(bottom: 20), - child: Text( - Months().getMonthShort(element.from.month)! + - " " + - element.from.day.toString() + - ", " + - timeF + - " - " + - Months().getMonthShort(element.to.month)! + - " " + - element.to.day.toString() + - ", " + - timeT), - ), - )); - } else { - dayClicked.add(Center( - child: Padding( - padding: const EdgeInsets.only(bottom: 20), - child: Text( - Months().getMonthShort(element.from.month)! + - " " + - element.from.day.toString() + - ", " + - element.from.year.toString() + - ", " + - timeF + - " - " + - Months().getMonthShort(element.to.month)! + - " " + - element.to.day.toString() + - ", " + - element.to.year.toString() + - ", " + - timeT), - ), - )); + if (element.from.day == element.to.day && + element.from.month == element.to.month && + element.from.year == element.to.year) { + secondLine = Center( + child: Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Text(timeF + " - " + timeT), + ), + ); + } else if (element.from.year == element.to.year) { + secondLine = Center( + child: Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Text(Months() + .getMonthShort(element.from.month)! + + " " + + element.from.day.toString() + + ", " + + timeF + + " - " + + Months().getMonthShort(element.to.month)! + + " " + + element.to.day.toString() + + ", " + + timeT), + ), + ); + } else { + secondLine = Center( + child: Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Text(Months() + .getMonthShort(element.from.month)! + + " " + + element.from.day.toString() + + ", " + + element.from.year.toString() + + ", " + + timeF + + " - " + + Months().getMonthShort(element.to.month)! + + " " + + element.to.day.toString() + + ", " + + element.to.year.toString() + + ", " + + timeT), + ), + ); + } + dayClicked.add(Column(children: [firstLine,secondLine],)); } - }); - } else { - dayClicked.add(const Text("No events today")); + ); + } else { + dayClicked.add(const Text("No events today")); + } } - } - int yearsPassed = 1; - if (pages > 12) { - temporaryM = (temporaryM % 12) + 1; - } - int userMonth = temporaryM; - temporaryM = pages; + int yearsPassed = 1; + if (pages > 12) { + temporaryM = (temporaryM % 12) + 1; + } + int userMonth = temporaryM; + temporaryM = pages; - var yearEarly = 1980; - yearsPassed = (pages / 12).floor(); - int earlyYear = yearEarly + yearsPassed; - String monthIAmIn = n.currentMonth; - if (n.now.month == userMonth && n.now.year == earlyYear) { - monthView = n; - } else { - monthView = Months.otherYears(userMonth, earlyYear); - } - int mdw = monthView.monthStart; - if (monthView.monthStart == 7) { - mdw = 0; - } - monthIAmIn = n.month[userMonth].toString(); + var yearEarly = 1980; + yearsPassed = (pages / 12).floor(); + int earlyYear = yearEarly + yearsPassed; + String monthIAmIn = n.currentMonth; + if (n.now.month == userMonth && n.now.year == earlyYear) { + monthView = n; + } else { + monthView = Months.otherYears(userMonth, earlyYear); + } + int mdw = monthView.monthStart; + if (monthView.monthStart == 7) { + mdw = 0; + } + monthIAmIn = n.month[userMonth].toString(); - String year = (yearEarly + yearsPassed).toString(); + String year = (yearEarly + yearsPassed).toString(); - if (getCurrentYear().toString() == year) { - year = ""; - } - Color clickedColor = Colors.white70; - pageController.addListener(() { - clickedPosition = -2; - }); - return Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Row( - children: [ - Center( - child: InkWell( - child: Container( - padding: - const EdgeInsets.only(bottom: 16, top: 10), - child: Align( - alignment: Alignment.center, - child: Text( - monthIAmIn + ' ' + year, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25), + if (getCurrentYear().toString() == year) { + year = ""; + } + Color clickedColor = Colors.white70; + pageController.addListener(() { + clickedPosition = -2; + }); + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + children: [ + Center( + child: InkWell( + child: Container( + padding: + const EdgeInsets.only(bottom: 16, top: 10), + child: Align( + alignment: Alignment.center, + child: Text( + monthIAmIn + ' ' + year, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25), + ), ), ), + onTap: () { + onYearPressed(context, pageController); + }, + borderRadius: BorderRadius.circular(200), ), - onTap: () { - onYearPressed(context, pageController); - }, - borderRadius: BorderRadius.circular(200), ), - ), - Padding( - child: InkWell( - onTap: () => onFindMyDayPressed(), - splashColor: Colors.red[400]!, - child: Container( - decoration: BoxDecoration( - color: Colors.transparent, - border: Border.all(color: Colors.red[400]!), - shape: BoxShape.circle, - ), - height: 25.0, - width: 25.0, - child: Center( - child: Text( - CalendarState().getCurrentDay().toString()), + Padding( + child: InkWell( + onTap: () => onFindMyDayPressed(), + splashColor: Colors.red[400]!, + child: Container( + decoration: BoxDecoration( + color: Colors.transparent, + border: Border.all(color: Colors.red[400]!), + shape: BoxShape.circle, + ), + height: 25.0, + width: 25.0, + child: Center( + child: Text(CalendarState() + .getCurrentDay() + .toString()), + ), ), ), + padding: + const EdgeInsets.only(left: 120, right: 15), ), - padding: const EdgeInsets.only(left: 120, right: 15), - ), - ], - //mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.end, - ), - Padding( - padding: const EdgeInsets.only(bottom: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: const [ - Text( - "Sun", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold), - ), - Text("Mon", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)), - Text("Tues", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)), - Text("Wed", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)), - Text("Thur", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)), - Text("Fri", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)), - Text("Sat", - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold)) ], + //mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.end, ), - ), - Expanded( - flex: 3, - //Builds grid of days based on number of days in month - child: GridView.builder( - itemCount: monthView.daysInMonth + mdw, - scrollDirection: Axis.vertical, - physics: const ScrollPhysics(), - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 7, - childAspectRatio: 1 / 1.1, - ), - itemBuilder: (BuildContext context, int index) { - index += 1; - int day; - bool skip = false; - if (mdw != 0) { - day = index - monthView.monthStart; - } else { - day = index; - skip = true; - } - Color textColor; - Widget textStyleToday = Text((day).toString()); - - if ((day) == monthView.now.day && - monthView.now.month == n.now.month && - monthView.now.year == n.now.year) { - textColor = Colors.white; - textStyleToday = CircleAvatar( - backgroundColor: Colors.red[400]!, - child: Text( - day.toString(), - style: TextStyle( - color: textColor, - fontWeight: FontWeight.bold), - ), - maxRadius: 12, - ); - } - if (clickedPosition == day) { - clickedColor = Colors.red[200]!; - } else { - clickedColor = Colors.white70; - } - - int dayLetters = index - 1; - - if (index <= monthView.monthStart && !skip) { - Color colorCard; - if (darkMode) { - colorCard = Colors.black; + Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: const [ + Text( + "Sun", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold), + ), + Text("Mon", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)), + Text("Tues", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)), + Text("Wed", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)), + Text("Thur", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)), + Text("Fri", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)), + Text("Sat", + style: TextStyle( + fontSize: 20, fontWeight: FontWeight.bold)) + ], + ), + ), + Expanded( + flex: 3, + //Builds grid of days based on number of days in month + child: GridView.builder( + itemCount: monthView.daysInMonth + mdw, + scrollDirection: Axis.vertical, + physics: const ScrollPhysics(), + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 7, + childAspectRatio: 1 / 1.1, + ), + itemBuilder: (BuildContext context, int index) { + index += 1; + int day; + bool skip = false; + if (mdw != 0) { + day = index - monthView.monthStart; } else { - colorCard = Colors.white; + day = index; + skip = true; } + Color textColor; + Widget textStyleToday = Text((day).toString()); - return Card( - color: colorCard, - elevation: 0, - ); - } else { - if (dayLetters >= 7) { - dayLetters = (dayLetters % 7); + if ((day) == monthView.now.day && + monthView.now.month == n.now.month && + monthView.now.year == n.now.year) { + textColor = Colors.white; + textStyleToday = CircleAvatar( + backgroundColor: Colors.red[400]!, + child: Text( + day.toString(), + style: TextStyle( + color: textColor, + fontWeight: FontWeight.bold), + ), + maxRadius: 12, + ); } - var todayE = globals.eventsList[day.toString() + - userMonth.toString() + - (yearEarly + yearsPassed).toString()]; - List dayInfo = []; - dayInfo.add(textStyleToday); - if (todayE != null) { - for (var element in todayE) { - dayInfo.add(Container( - padding: const EdgeInsets.only(top: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 2, - width: 40, - )); - } + if (clickedPosition == day) { + clickedColor = Colors.red[200]!; + } else { + clickedColor = Colors.white70; } - if (globals.everyDay.isNotEmpty) { - for (var element in globals.everyDay) { - if (temporaryM >= element.page) { - if (element.from.year == - (yearsPassed + yearEarly) && - element.from.month == userMonth) { - if (day >= element.from.day) { + int dayLetters = index - 1; + + if (index <= monthView.monthStart && !skip) { + Color colorCard; + if (darkMode) { + colorCard = Colors.black; + } else { + colorCard = Colors.white; + } + + return Card( + color: colorCard, + elevation: 0, + ); + } else { + if (dayLetters >= 7) { + dayLetters = (dayLetters % 7); + } + var todayE = globals.eventsList[day.toString() + + userMonth.toString() + + (yearEarly + yearsPassed).toString()]; + List dayInfo = []; + dayInfo.add(textStyleToday); + if (todayE != null) { + for (var element in todayE) { + dayInfo.add(Container( + padding: const EdgeInsets.only(top: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 2, + width: 40, + )); + } + } + + if (globals.everyDay.isNotEmpty) { + for (var element in globals.everyDay) { + if (temporaryM >= element.page) { + if (element.from.year == + (yearsPassed + yearEarly) && + element.from.month == userMonth) { + if (day >= element.from.day) { + dayInfo.add(Container( + padding: + const EdgeInsets.only(top: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 2, + width: 40, + )); + } + } else { dayInfo.add(Container( padding: const EdgeInsets.only(top: 10), @@ -369,62 +402,64 @@ class CalendarState extends State { width: 40, )); } - } else { - dayInfo.add(Container( - padding: const EdgeInsets.only(top: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 2, - width: 40, - )); } } } - } - if (globals.everyWeek.isNotEmpty) { - for (var element in globals.everyWeek) { - if (temporaryM >= element.page) { - DateTime weekDay = DateTime( - yearEarly + yearsPassed, - userMonth, - day); - if (element.to - .difference(element.from) - .inDays != - 0) { - for (int i = 0; - i <= - element.to - .difference(element.from) - .inDays; - i++) { - int dayCalc = element.from.day + i; - int month = element.from.month; - int yearCalc = element.from.year; + if (globals.everyWeek.isNotEmpty) { + for (var element in globals.everyWeek) { + if (temporaryM >= element.page) { + DateTime weekDay = DateTime( + yearEarly + yearsPassed, + userMonth, + day); + if (element.to + .difference(element.from) + .inDays != + 0) { + for (int i = 0; + i <= + element.to + .difference(element.from) + .inDays; + i++) { + int dayCalc = element.from.day + i; + int month = element.from.month; + int yearCalc = element.from.year; - if (dayCalc > - DateTime(element.from.year, - element.from.month + 1, 0) - .day) { - dayCalc = 1; - month += 1; - } - if (month > 12) { - if (month % 12 == 0) { - yearCalc += month~/12; + if (dayCalc > + DateTime(element.from.year, + element.from.month + 1, 0) + .day) { + dayCalc = 1; + month += 1; } - month = 1; - } - int dayOffset = - DateTime(yearCalc, month, dayCalc) - .weekday; + if (month > 12) { + if (month % 12 == 0) { + yearCalc += month ~/ 12; + } + month = 1; + } + int dayOffset = + DateTime(yearCalc, month, dayCalc) + .weekday; - if (weekDay.weekday == dayOffset) { - if (yearCalc == - (yearsPassed + yearEarly) && - month == userMonth) { - if (day >= dayCalc) { + if (weekDay.weekday == dayOffset) { + if (yearCalc == + (yearsPassed + yearEarly) && + month == userMonth) { + if (day >= dayCalc) { + dayInfo.add(Container( + padding: + const EdgeInsets.only( + top: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 2, + width: 40, + )); + } + } else { dayInfo.add(Container( padding: const EdgeInsets.only( top: 10), @@ -435,7 +470,14 @@ class CalendarState extends State { width: 40, )); } - } else { + } + } + } else if (weekDay.weekday == + (element.from.weekday)) { + if (element.from.year == + (yearsPassed + yearEarly) && + element.from.month == userMonth) { + if (day >= element.from.day) { dayInfo.add(Container( padding: const EdgeInsets.only( top: 10), @@ -446,14 +488,7 @@ class CalendarState extends State { width: 40, )); } - } - } - } else if (weekDay.weekday == - (element.from.weekday)) { - if (element.from.year == - (yearsPassed + yearEarly) && - element.from.month == userMonth) { - if (day >= element.from.day) { + } else { dayInfo.add(Container( padding: const EdgeInsets.only(top: 10), @@ -464,48 +499,52 @@ class CalendarState extends State { width: 40, )); } - } else { - dayInfo.add(Container( - padding: - const EdgeInsets.only(top: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 2, - width: 40, - )); } } } } - } - if (globals.everyMonth.isNotEmpty) { - for (var element in globals.everyMonth) { - if (element.to - .difference(element.from) - .inDays != - 0) { - for (int i = 0; - i <= - element.to - .difference(element.from) - .inDays; - i++) { - int dayCalc = element.from.day + i; - int monthCalc = element.from.month; + if (globals.everyMonth.isNotEmpty) { + for (var element in globals.everyMonth) { + if (element.to + .difference(element.from) + .inDays != + 0) { + for (int i = 0; + i <= + element.to + .difference(element.from) + .inDays; + i++) { + int dayCalc = element.from.day + i; + int monthCalc = element.from.month; - if (dayCalc > - DateTime(element.from.year, - element.from.month + 1, 0) - .day) { - dayCalc = 1; - monthCalc += 1; - } - if (monthCalc > 12) { - monthCalc = 1; + if (dayCalc > + DateTime(element.from.year, + element.from.month + 1, 0) + .day) { + dayCalc = 1; + monthCalc += 1; + } + if (monthCalc > 12) { + monthCalc = 1; + } + if (day == dayCalc) { + if (temporaryM >= element.page) { + dayInfo.add(Container( + padding: const EdgeInsets.only( + top: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 2, + width: 40, + )); + } + } } - if (day == dayCalc) { + } else { + if (day == element.from.day) { if (temporaryM >= element.page) { dayInfo.add(Container( padding: @@ -519,54 +558,56 @@ class CalendarState extends State { } } } - } else { - if (day == element.from.day) { - if (temporaryM >= element.page) { - dayInfo.add(Container( - padding: - const EdgeInsets.only(top: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 2, - width: 40, - )); - } - } } } - } - if (globals.everyYear.isNotEmpty) { - for (var element in globals.everyYear) { - if (element.to - .difference(element.from) - .inDays != - 0) { - for (int i = 0; - i <= - element.to - .difference(element.from) - .inDays; - i++) { - int dayCalc = element.from.day + i; - int month = element.from.month; + if (globals.everyYear.isNotEmpty) { + for (var element in globals.everyYear) { + if (element.to + .difference(element.from) + .inDays != + 0) { + for (int i = 0; + i <= + element.to + .difference(element.from) + .inDays; + i++) { + int dayCalc = element.from.day + i; + int month = element.from.month; - if (dayCalc > - DateTime(element.from.year, - element.from.month + 1, 0) - .day) { - dayCalc = 1; - month += 1; - } - if (month > 12) { - month = 1; - } + if (dayCalc > + DateTime(element.from.year, + element.from.month + 1, 0) + .day) { + dayCalc = 1; + month += 1; + } + if (month > 12) { + month = 1; + } - if (day == dayCalc && - userMonth == month) { + if (day == dayCalc && + userMonth == month) { + if (temporaryM >= element.page) { + dayInfo.add(Container( + padding: const EdgeInsets.only( + top: 10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + color: element.color), + height: 2, + width: 40, + )); + } + } + } + } else { + if (day == element.from.day && + userMonth == element.from.month) { if (temporaryM >= element.page) { dayInfo.add(Container( - padding: const EdgeInsets.only(top: 10), + padding: + const EdgeInsets.only(top: 10), decoration: BoxDecoration( shape: BoxShape.rectangle, color: element.color), @@ -577,76 +618,161 @@ class CalendarState extends State { } } } - else { - if (day == element.from.day && - userMonth == element.from.month) { - if (temporaryM >= element.page) { - dayInfo.add(Container( - padding: const EdgeInsets.only(top: 10), - decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: element.color), - height: 2, - width: 40, - )); - } - } - } } - } - return SizedBox( - height: 200, - child: Card( - shape: RoundedRectangleBorder( - side: BorderSide( - color: clickedColor, width: 1), - borderRadius: BorderRadius.circular(10), - ), - child: InkWell( - borderRadius: BorderRadius.circular(50), - splashColor: Colors.deepOrangeAccent, - child: Align( - alignment: Alignment.topCenter, - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - children: dayInfo, + return SizedBox( + height: 200, + child: Card( + shape: RoundedRectangleBorder( + side: BorderSide( + color: clickedColor, width: 1), + borderRadius: BorderRadius.circular(10), + ), + child: InkWell( + borderRadius: BorderRadius.circular(50), + splashColor: Colors.deepOrangeAccent, + child: Align( + alignment: Alignment.topCenter, + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + children: dayInfo, + ), ), + onTap: () => _tapDate( + day, + yearEarly + yearsPassed, + userMonth, + temporaryM), ), - onTap: () => _tapDate( - day, - yearEarly + yearsPassed, - userMonth, - temporaryM), ), - ), - ); - } - }), - ), - Expanded( - flex: 1, - child: ListView( - children: [ - Column( - children: dayClicked, - ), - ], - )), - ], - ); - }, + ); + } + }), + ), + Expanded( + flex: 1, + child: ListView.builder( + itemCount: dayClicked.length, + itemBuilder: (BuildContext context, int index) { + return InkWell( + onTap: () { + if (deleteSearch[index].type == "assignment") { + } + + }, + onLongPress: () { + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: const Text('Delete event?'), + content: const Text('Can\'t be undone'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () { + String d = deleteSearch[index].from.day.toString(); + String m = deleteSearch[index].from.month.toString(); + String y = deleteSearch[index].from.year.toString(); + print(deleteSearch[index].title); + print(deleteSearch[index].from.day); + print("In long press"); + + if (deleteSearch[index].to.difference(deleteSearch[index].from).inDays != 0) { + //print("i am here"); + //print(deleteSearch[index].from.difference(deleteSearch[index].to).inDays); + for (int j = 0; j <= deleteSearch[index].to.difference(deleteSearch[index].from).inDays; j++) { + d = (deleteSearch[index].from.day + j).toString(); + print(d); + for (int i = 0; i < (globals.eventsList[d + m + y]?.length)!; i++) { + print(globals.eventsList[d + m + y]?.length); + + if (globals.eventsList[d + m + y]?.elementAt(i).to.day == deleteSearch[index].to.day && + globals.eventsList[d + m + y]?.elementAt(i).to.month == deleteSearch[index].to.month && + globals.eventsList[d + m + y]?.elementAt(i).to.year == deleteSearch[index].to.year && + globals.eventsList[d + m + y]?.elementAt(i).to.hour == deleteSearch[index].to.hour && + globals.eventsList[d + m + y]?.elementAt(i).to.minute == deleteSearch[index].to.minute && + globals.eventsList[d + m + y]?.elementAt(i).from.day == deleteSearch[index].from.day && + globals.eventsList[d + m + y]?.elementAt(i).from.minute == deleteSearch[index].from.minute && + globals.eventsList[d + m + y]?.elementAt(i).from.year == deleteSearch[index].from.year && + globals.eventsList[d + m + y]?.elementAt(i).from.month == deleteSearch[index].from.month && + globals.eventsList[d + m + y]?.elementAt(i).from.hour == deleteSearch[index].from.hour && + globals.eventsList[d + m + y]?.elementAt(i).type == deleteSearch[index].type && + globals.eventsList[d + m + y]?.elementAt(i).allDay == deleteSearch[index].allDay && + globals.eventsList[d + m + y]?.elementAt(i).page == deleteSearch[index].page && + globals.eventsList[d + m + y]?.elementAt(i).title == deleteSearch[index].title + ) { + + globals.eventsList[d + m + y]?.removeAt(i); + print("hm"); + + } + } + } + _tapDate(deleteSearch[index].from.day, deleteSearch[index].from.year, deleteSearch[index].from.month, pag); + } + else { + for (int i = 0; i < (globals.eventsList[d + m + y]?.length)!; i++) { + if (globals.eventsList[d + m + y]?.elementAt(i).to.day == deleteSearch[index].to.day && + globals.eventsList[d + m + y]?.elementAt(i).to.month == deleteSearch[index].to.month && + globals.eventsList[d + m + y]?.elementAt(i).to.year == deleteSearch[index].to.year && + globals.eventsList[d + m + y]?.elementAt(i).to.hour == deleteSearch[index].to.hour && + globals.eventsList[d + m + y]?.elementAt(i).to.minute == deleteSearch[index].to.minute && + globals.eventsList[d + m + y]?.elementAt(i).from.day == deleteSearch[index].from.day && + globals.eventsList[d + m + y]?.elementAt(i).from.minute == deleteSearch[index].from.minute && + globals.eventsList[d + m + y]?.elementAt(i).from.year == deleteSearch[index].from.year && + globals.eventsList[d + m + y]?.elementAt(i).from.month == deleteSearch[index].from.month && + globals.eventsList[d + m + y]?.elementAt(i).from.hour == deleteSearch[index].from.hour && + globals.eventsList[d + m + y]?.elementAt(i).type == deleteSearch[index].type && + globals.eventsList[d + m + y]?.elementAt(i).allDay == deleteSearch[index].allDay && + globals.eventsList[d + m + y]?.elementAt(i).page == deleteSearch[index].page && + globals.eventsList[d + m + y]?.elementAt(i).title == deleteSearch[index].title + ) { + globals.eventsList[d + m + y]?.removeAt(i); + _tapDate(deleteSearch[index].from.day, deleteSearch[index].from.year, deleteSearch[index].from.month, pag); + + } + } + } + + Navigator.pop(context); + }, + child: const Text('Delete'), + ), + ], + )); + + }, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + dayClicked[index], + ])); + }, + //children: [ + //Column( + //children: dayClicked, + //), + //], + )), + ], + ); + }, + ), ), - ), - ], + ], + ), ), ); } void _tapDate(int day, int year, int month, int page) { dayClicked.clear(); - + deleteSearch.clear(); setState(() { clickedPosition = day; }); @@ -691,7 +817,7 @@ class CalendarState extends State { } if (monthCalc > 12) { if (month % 12 == 0) { - yearCalc += month~/12; + yearCalc += month ~/ 12; } monthCalc = 1; } @@ -740,7 +866,7 @@ class CalendarState extends State { } if (monthCalc > 12) { if (month % 12 == 0) { - yearCalc += month~/12; + yearCalc += month ~/ 12; } monthCalc = 1; } @@ -773,30 +899,22 @@ class CalendarState extends State { } if (globals.everyYear.isNotEmpty) { for (var element in globals.everyYear) { - if (element.to - .difference(element.from) - .inDays != - 0) { + if (element.to.difference(element.from).inDays != 0) { for (int i = 0; - i <= - element.to - .difference(element.from) - .inDays; - i++) { + i <= element.to.difference(element.from).inDays; + i++) { int dayCalc = element.from.day + i; int monthCalc = element.from.month; int yearCalc = element.from.year; if (dayCalc > - DateTime(element.from.year, - element.from.month + 1, 0) - .day) { + DateTime(element.from.year, element.from.month + 1, 0).day) { dayCalc = 1; month += 1; } if (month > 12) { if (month % 12 == 0) { - yearCalc += month~/12; + yearCalc += month ~/ 12; } month = 1; } @@ -812,8 +930,7 @@ class CalendarState extends State { } } } - } - else { + } else { if (day == element.from.day && month == element.from.month) { if (page >= element.page) { if (element.from.year == year && element.from.month == month) { @@ -826,12 +943,14 @@ class CalendarState extends State { } } } - } } + Widget firstLine = Spacer(); + Widget secondLine = Spacer(); + if (temp.isNotEmpty) { for (var element in temp) { - dayClicked.add(Row( + firstLine = Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( @@ -847,7 +966,7 @@ class CalendarState extends State { style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 20), ), ], - )); + ); String timeF = TimeOfDay(hour: element.from.hour, minute: element.from.minute) .format(context); @@ -858,23 +977,23 @@ class CalendarState extends State { element.from.month == element.to.month && element.from.year == element.to.year) { if (element.allDay) { - dayClicked.add(const Center( + secondLine = const Center( child: Padding( padding: EdgeInsets.only(bottom: 20), child: Text("All day"), ), - )); + ); } else { - dayClicked.add(Center( + secondLine = Center( child: Padding( padding: const EdgeInsets.only(bottom: 20), child: Text(timeF + " - " + timeT), ), - )); + ); } } else if (element.from.year == element.to.year) { if (element.allDay) { - dayClicked.add(Center( + secondLine = Center( child: Padding( padding: const EdgeInsets.only(bottom: 20), child: Text(Months().getMonthShort(element.from.month)! + @@ -885,9 +1004,9 @@ class CalendarState extends State { " " + element.to.month.toString()), ), - )); + ); } else { - dayClicked.add(Center( + secondLine = Center( child: Padding( padding: const EdgeInsets.only(bottom: 20), child: Text(Months().getMonthShort(element.from.month)! + @@ -902,11 +1021,11 @@ class CalendarState extends State { ", " + timeT), ), - )); + ); } } else { if (element.allDay) { - dayClicked.add(Center( + secondLine = Center( child: Padding( padding: const EdgeInsets.only(bottom: 20), child: Text(Months().getMonthShort(element.from.month)! + @@ -921,9 +1040,9 @@ class CalendarState extends State { ", " + element.to.year.toString()), ), - )); + ); } else { - dayClicked.add(Center( + secondLine = Center( child: Padding( padding: const EdgeInsets.only(bottom: 20), child: Text(Months().getMonthShort(element.from.month)! + @@ -942,18 +1061,22 @@ class CalendarState extends State { ", " + timeT), ), - )); + ); } } + dayClicked.add(Column( + children: [firstLine, secondLine], + )); + deleteSearch.add(element); } } else { - dayClicked.add(const Text("No events today")); + dayClicked.add(const Center(child: Text("No events today"))); } + final access = StateWidget.of(context); access?.updateClicked(day, year, month); DatabaseReference _day = FirebaseDatabase.instance.ref().child("test"); _day.set("Day tapped: ${day}"); - print(day); } void navigationPress(int month, int year, BuildContext context) { @@ -1030,7 +1153,7 @@ class CalendarState extends State { display = (firstYearRange.toString() + "-" + (firstYearRange + 12).toString()); - print(display); + //print(display); }); }, ), @@ -1069,4 +1192,13 @@ class CalendarState extends State { ); }); } + + void onAddEventButtonPressed() { + Navigator.of(context).push(MaterialPageRoute(builder: (context) { + int? clicked = StateWidget.of(context)?.clicked; + + //print(clicked); + return EventForm(); + })); + } } diff --git a/lib/event_form.dart b/lib/event_form.dart index 094b993..d333386 100644 --- a/lib/event_form.dart +++ b/lib/event_form.dart @@ -1,10 +1,12 @@ +import 'package:day_to_day/event_list_storage.dart'; import 'package:day_to_day/inherited.dart'; +import 'events.dart'; import 'package:day_to_day/months.dart'; import 'package:day_to_day/main.dart'; import 'package:flutter/material.dart'; class EventForm extends StatefulWidget { - const EventForm({Key? key}) : super(key: key); + EventForm({Key? key}) : super(key: key); @override EventFormState createState() => EventFormState(); @@ -46,6 +48,7 @@ class EventFormState extends State { String colorChosenText = "Default"; TimeOfDay fromObj = TimeOfDay.now(); TimeOfDay toObj = TimeOfDay.now(); + String type = "calendar"; int hourF = 0; int minuteF = 0; int minuteT = 0; @@ -55,14 +58,15 @@ class EventFormState extends State { @override Widget build(BuildContext context) { - String to; String title = "Default Event"; + String to; int dayF = (StateWidget.of(context)?.clicked)!; int weekDayN; int hour = n.now.hour; int minute = n.now.minute; String? weekD; bool pastSixty = false; + if (dayF == -2 && !chosenFrom) { selectedTime = n.now; } else if (!chosenFrom) { @@ -97,10 +101,18 @@ class EventFormState extends State { } if (hour > 12) { - var hourReduced = hour %12; - //hour %= 12; - timeFrom = hourReduced.toString() + ":" + minuteStr + " PM"; - } else if (hour == 12) { + if (hour == 24) { + var hourReduced = 12; + timeFrom = hourReduced.toString() + ":" + minuteStr + " AM"; + } + else { + var hourReduced = hour %12; + //hour %= 12; + timeFrom = hourReduced.toString() + ":" + minuteStr + " PM"; + } + + } + else if (hour == 12) { timeFrom = hour.toString() + ":" + minuteStr + " PM"; } else { var hourReduced = hour; @@ -121,6 +133,7 @@ class EventFormState extends State { hour += 1; } String minuteStr = minute.toString(); + if (minute == 0) { minuteStr = minuteStr.toString() + "0"; } @@ -129,6 +142,11 @@ class EventFormState extends State { midnight +=1; timeTo = hourReduced.toString() + ":" + minuteStr + " AM"; } + if (hour == 25) { + var hourReduced = 1; + midnight +=1; + timeTo = hourReduced.toString() + ":" + minuteStr + " AM"; + } else if (hour > 12) { var hourReduced = hour % 12; //hour %= 12; @@ -143,7 +161,6 @@ class EventFormState extends State { timeTo = hourReduced.toString() + ":" + minuteStr + " AM"; } finalTimeTo = timeTo; - print(hour); hourT = hour; minuteT = minute; } @@ -176,7 +193,10 @@ class EventFormState extends State { ", " + (selectedTime.year.toString()); } - + Color disable = Colors.white; + if (type != "calendar") { + disable = Colors.grey; + } return InheritedState( child: Scaffold( @@ -201,6 +221,60 @@ class EventFormState extends State { ), ), const Divider(color: Colors.grey,), + Padding(padding: const EdgeInsets.only( + top: 12, bottom: 12, left: 20, right: 20), + child: Center( + child: Column( + children: [ + const Text("Event Type: "), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + style: type.contains("calendar") ? ElevatedButton.styleFrom(side: BorderSide( + color: Colors.red[200]!, width: 1)) + : ElevatedButton.styleFrom(side: BorderSide( + color: Colors.blue[100]!, width: 1)), + onPressed: () { + setState(() { + type = "calendar"; + }); + }, + child: const Center(child: Text("Calendar"))), + ElevatedButton( + style: type.contains("assignment") ? ElevatedButton.styleFrom(side: BorderSide( + color: Colors.red[200]!, width: 1)) + : ElevatedButton.styleFrom(side: BorderSide( + color: Colors.blue[100]!, width: 1)), + onPressed: () { + setState(() { + type = "assignment"; + }); + }, + child: const Center(child: Text("Assignment"))), + ElevatedButton( + style: type.contains("project") ? ElevatedButton.styleFrom(side: BorderSide( + color: Colors.red[200]!, width: 1)) + : ElevatedButton.styleFrom(side: BorderSide( + color: Colors.blue[100]!, width: 1)), + onPressed: () { + setState(() { + type = "project"; + }); + }, + child: const Center(child: Text("Project"))), + ElevatedButton( + style: type.contains("exam") ? ElevatedButton.styleFrom(side: BorderSide( + color: Colors.red[200]!, width: 1)) + : ElevatedButton.styleFrom(side: BorderSide( + color: Colors.blue[100]!, width: 1)), + onPressed: () { + setState(() { + type = "exam"; + }); + }, + child: const Center(child: Text("Exam")))] + )]),)), InkWell( child: Row( children: [ @@ -292,7 +366,7 @@ class EventFormState extends State { child: SizedBox( child: Text( repeatD, - style: const TextStyle(fontSize: 20), + style: TextStyle(fontSize: 20, color: disable), ), height: 45, ), @@ -300,7 +374,7 @@ class EventFormState extends State { ], ), onTap: () { - onRepeat(); + onRepeat(type); }, ), const Divider(color: Colors.grey,), @@ -370,16 +444,17 @@ class EventFormState extends State { ), TextButton( onPressed: () { - //print(title); + //If the event was saved, write it to the respective file + //!!!!!!TODO!!!!! if (selectedTimeTo != null) { StateWidget.of(context)?.addEvent(selectedTime.day, selectedTime.year, selectedTime.month, title, finalTimeFrom, finalTimeTo, (selectedTimeTo?.day)!, (selectedTimeTo?.month)!, (selectedTimeTo?.year)!, colorChosenBubble, toObj, fromObj, isSwitched, repeatD, - (selectedTime.year - 1980) * 12 + selectedTime.month - 1, hourF, hourT, minuteF, minuteT, eventType); + (selectedTime.year - 1980) * 12 + selectedTime.month - 1, hourF, hourT, minuteF, minuteT, type); } else { StateWidget.of(context)?.addEvent(selectedTime.day, selectedTime.year, selectedTime.month, title, finalTimeFrom, finalTimeTo, selectedTime.day, selectedTime.month, - selectedTime.year, colorChosenBubble, toObj, fromObj, isSwitched, repeatD, (selectedTime.year - 1980) * 12 + selectedTime.month - 1, hourF, hourT, minuteF, minuteT, eventType); + selectedTime.year, colorChosenBubble, toObj, fromObj, isSwitched, repeatD, (selectedTime.year - 1980) * 12 + selectedTime.month - 1, hourF, hourT, minuteF, minuteT, type); } streamController.add(true); Navigator.pop(context); @@ -415,41 +490,42 @@ class EventFormState extends State { Future chooseFromDay( BuildContext context, DateTime current, bool fromChoose) async { - DateTime? userChosenFrom = (await showDatePicker( - builder: (context, child) { - return Theme( - data: Theme.of(context).copyWith( - colorScheme: ColorScheme.dark( - primary: Colors.red[200]!, - onPrimary: Colors.white, - onSurface: Colors.white, - ), - textButtonTheme: TextButtonThemeData( - style: TextButton.styleFrom( - primary: Colors.red[200], - ), - ), - ), child: child!, - )}, - context: context, - initialDate: current, - firstDate: DateTime(1980, 1), - lastDate: DateTime(2222)))!; - if (fromChoose) { - if (userChosenFrom != current) { - chosenFrom = true; - setState(() { - selectedTime = userChosenFrom; + DateTime? userChosenFrom = (await showDatePicker( + builder: (context, child) { + return Theme( + data: Theme.of(context).copyWith( + colorScheme: ColorScheme.dark( + primary: Colors.red[200]!, + onPrimary: Colors.white, + onSurface: Colors.white, + ), + textButtonTheme: TextButtonThemeData( + style: TextButton.styleFrom( + primary: Colors.red[200], + ), + ), + ), child: child!, + )}, + context: context, + initialDate: current, + firstDate: DateTime(1980, 1), + lastDate: DateTime(2222)))!; + + if (fromChoose) { + if (userChosenFrom != current) { + chosenFrom = true; + setState(() { + selectedTime = userChosenFrom; - }); - } - } else { - chosenTo = true; - setState(() { - selectedTimeTo = userChosenFrom; - }); + }); + } + } else { + chosenTo = true; + setState(() { + selectedTimeTo = userChosenFrom; + }); - } + } } @@ -489,91 +565,95 @@ class EventFormState extends State { } } - void onRepeat() { + void onRepeat(String type) { + if (type == "calendar") { showDialog(context: context, builder: (context) { return StatefulBuilder( - builder: (context, setState) { - return Dialog( - elevation: 20, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)), - child: SizedBox( - height: 300, - child: Column( - children: [ - RadioListTile( - title: const Text("Don't Repeat"), - value: SingingCharacter.none, - groupValue: repeatingChoose, - onChanged: (SingingCharacter? value) { - Navigator.pop(context, true); - setState(() { - repeatD = "Don't Repeat"; - repeatingChoose = value; - }); - } - ), - RadioListTile( - title: const Text("Everyday"), - value: SingingCharacter.daily, - groupValue: repeatingChoose, - onChanged: (SingingCharacter? value) { - Navigator.pop(context, true); - setState(() { - repeatD = "Everyday"; - repeatingChoose = value; - }); - } - ), - RadioListTile( - title: const Text("Every week"), - value: SingingCharacter.weekly, - groupValue: repeatingChoose, - onChanged: (SingingCharacter? value) { - Navigator.pop(context, true); - setState(() { - repeatD = "Every week"; - repeatingChoose = value; - }); - } - ), - RadioListTile( - title: const Text("Every month"), - value: SingingCharacter.monthly, - groupValue: repeatingChoose, - onChanged: (SingingCharacter? value) { - Navigator.pop(context,true); - setState(() { - repeatD = "Every month"; - repeatingChoose = value; - }); - } - ), - RadioListTile( - title: const Text("Every year"), - value: SingingCharacter.yearly, - groupValue: repeatingChoose, - onChanged: (SingingCharacter? value) { - Navigator.pop(context, true); - - setState(() { - repeatD = "Every year"; - repeatingChoose = value; - }); - } - ), + builder: (context, setState) { + return Dialog( + elevation: 20, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)), + child: SizedBox( + height: 300, + child: Column( + children: [ + RadioListTile( + title: const Text("Don't Repeat"), + value: SingingCharacter.none, + groupValue: repeatingChoose, + onChanged: (SingingCharacter? value) { + Navigator.pop(context, true); + setState(() { + repeatD = "Don't Repeat"; + repeatingChoose = value; + }); + } + ), + RadioListTile( + title: const Text("Everyday"), + value: SingingCharacter.daily, + groupValue: repeatingChoose, + onChanged: (SingingCharacter? value) { + Navigator.pop(context, true); + setState(() { + repeatD = "Everyday"; + repeatingChoose = value; + }); + } + ), + RadioListTile( + title: const Text("Every week"), + value: SingingCharacter.weekly, + groupValue: repeatingChoose, + onChanged: (SingingCharacter? value) { + Navigator.pop(context, true); + setState(() { + repeatD = "Every week"; + repeatingChoose = value; + }); + } + ), + RadioListTile( + title: const Text("Every month"), + value: SingingCharacter.monthly, + groupValue: repeatingChoose, + onChanged: (SingingCharacter? value) { + Navigator.pop(context,true); + setState(() { + repeatD = "Every month"; + repeatingChoose = value; + }); + } + ), + RadioListTile( + title: const Text("Every year"), + value: SingingCharacter.yearly, + groupValue: repeatingChoose, + onChanged: (SingingCharacter? value) { + Navigator.pop(context, true); + + setState(() { + repeatD = "Every year"; + repeatingChoose = value; + }); + } + ), - ], - ), - ) - ); - }); + ], + ), + ) + ); + }); }).then((value) { setState(() { }); }); + } + + } void onColor() { diff --git a/lib/event_list_storage.dart b/lib/event_list_storage.dart new file mode 100644 index 0000000..3c20eea --- /dev/null +++ b/lib/event_list_storage.dart @@ -0,0 +1,117 @@ +import 'package:flutter/material.dart'; +import 'dart:convert'; +import 'events.dart'; +import 'package:path_provider/path_provider.dart'; +import 'dart:io'; + +// This class is used to read and write files in the application +class EventListStorage { + var typeName = ""; + EventListStorage(this.typeName); + + Future get _localPath async { + final directory = await getApplicationDocumentsDirectory(); + + return directory.path; + } + + Future get _localFile async { + final path = await _localPath; + File file = File('$path/$typeName.txt'); + if (!await file.exists()) { + file.writeAsString(""); + } + return file; + } + + Future> readEvents() async { + final file = await _localFile; + + // Read the file + final contents = await file.readAsString(); + + List events = []; + DateTime from = DateTime.now(); + DateTime to = DateTime.now(); + int dayT = 0; + int monthT = 0; + int yearT = 0; + int dayF = 0; + int monthF = 0; + int yearF = 0; + int page = 0; + String type = ""; + String title = ""; + Color color; + bool allDay; + + if (contents.isEmpty) { + return []; + } + + var data = contents.split(":"); + for (int i = 0; i < data.length / 11; i++) { + type = data[i * 11]; + monthF = int.parse(data[i * 11 + 1]); + monthT = int.parse(data[i * 11 + 2]); + yearF = int.parse(data[i * 11 + 3]); + page = int.parse(data[i * 11 + 4]); + yearT = int.parse(data[i * 11 + 5]); + dayT = int.parse(data[i * 11 + 6]); + dayF = int.parse(data[i * 11 + 7]); + title = data[i * 11 + 8]; + color = data[i * 11 + 9] as Color; + if (data[i * 11 + 10].contains("rue")) { + allDay = true; + } else { + allDay = false; + } + + from = DateTime(yearF, monthF, dayF, 0, 0, 0, 0, 0); + to = DateTime(yearT, monthT, dayT, 0, 0, 0, 0, 0); + + events.add(Events(title, color, allDay, page, from, to, type)); + } + + return events; + } + + Future writeEvents(List events) async { + //This is the file + final file = await _localFile; + + //Set globals.timestamp = date.now() every time you write + + /*Every event has + DateTime from; + DateTime to; + int page = 0; + String type = ""; + String title = ""; + Color color; + bool allDay;*/ + + for (int i = 0; i < events.length; i++) { + file.writeAsString(events[i].from.toIso8601String()); + file.writeAsString(events[i].to.toIso8601String()); + file.writeAsString(events[i].page.toString()); + file.writeAsString(events[i].type); + file.writeAsString(events[i].title); + file.writeAsString(events[i].color.toString()); + if (events[i].allDay) { + file.writeAsString("True"); + } else { + file.writeAsString("False"); + } + } + + return file; + } + + Future writeEvent(Events event) async { + final file = await _localFile; + List oldList = await readEvents(); + oldList.add(event); + return writeEvents(oldList); + } +} diff --git a/lib/events.dart b/lib/events.dart index 64ec52c..ceac4e5 100644 --- a/lib/events.dart +++ b/lib/events.dart @@ -7,9 +7,9 @@ class Events { String title = ""; Color color; bool allDay; - String eventType; + String type; -Events(this.title, this.color, - this.allDay, this.page, this.from, this.to, this.eventType); + Events(this.title, this.color, + this.allDay, this.page, this.from, this.to, this.type); } \ No newline at end of file diff --git a/lib/events_widget.dart b/lib/events_widget.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/exams.dart b/lib/exams.dart new file mode 100644 index 0000000..d464afb --- /dev/null +++ b/lib/exams.dart @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'event_form.dart'; +import 'globals.dart' as globals; +import 'events.dart'; + +class ExamsWidget extends StatefulWidget { + List exams = []; + ExamsWidget({Key? key, required this.stream}) : super(key: key); + final Stream stream; + + @override + State createState() => ExamsState(); +} + +class ExamsState extends State { + @override + void initState() { + + widget.stream.listen((event) { + setState(() { + + }); + }); + super.initState(); + } + @override + Widget build(BuildContext context) { + widget.exams = []; + globals.eventsList.forEach((key, value) { + for (int i = 0; i < value.length; i++) { + if (value[i].type.contains("exam")) { + widget.exams.add(value[i]); + } + } + }); + return Scaffold( + appBar: AppBar( + title: const Center(child: Text("Exams List")), + backgroundColor: const Color.fromARGB(255, 255, 82, 82), + ), + body: ListView.builder( + itemCount: widget.exams.length, + itemBuilder: (BuildContext context, int index) { + return Card( + child: CheckboxListTile( + dense: true, + activeColor: Colors.red[400], + controlAffinity: ListTileControlAffinity.leading, + value: false, + onChanged: (value) { + setState(() { + widget.exams.removeAt(index); + }); + }, + title: Text( + widget.exams[index].title, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Color.fromARGB(255, 12, 12, 12)), + ))); + }, + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + setState(() { + Navigator.of(context).push(MaterialPageRoute(builder: (context) { + return EventForm(); + })); + }); + setState(() {}); + }); + }, + child: const Icon( + Icons.add, + size: 45, + color: Colors.white, + ), + backgroundColor: Colors.blueGrey, + ), + ); + } +} diff --git a/lib/globals.dart b/lib/globals.dart index 44c9219..09a25db 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,6 +1,7 @@ import 'events.dart'; Map> eventsList = {}; +List projects = []; List everyDay = []; List everyMonth = []; List everyWeek = []; diff --git a/lib/main.dart b/lib/main.dart index 93b4588..61d23b4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,14 +1,16 @@ import 'package:day_to_day/inherited.dart'; import 'package:day_to_day/login_widget.dart'; -import 'package:day_to_day/months.dart'; +import 'package:day_to_day/events.dart'; +import 'package:day_to_day/projects_widget.dart'; +import 'package:day_to_day/assignments.dart'; +import 'package:day_to_day/exams.dart'; import 'package:day_to_day/to_do_list_directory_widget.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; -import 'package:firebase_database/firebase_database.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:day_to_day/calendar.dart'; -import 'package:day_to_day/event_form.dart'; import 'dart:async'; +import 'event_list_storage.dart'; StreamController streamController = StreamController.broadcast(); @@ -67,7 +69,7 @@ class DayToDay extends StatelessWidget { stream: FirebaseAuth.instance.authStateChanges(), builder: (context, snapshot) { if (snapshot.hasData) { - return const AppWidget(); + return AppWidget(); } else if (snapshot.hasError) { return const Center( child: Text('Error'), @@ -85,29 +87,35 @@ class DayToDay extends StatelessWidget { } class AppWidget extends StatefulWidget { - const AppWidget({Key? key}) : super(key: key); + AppWidget({Key? key}) : super(key: key); + List eventList = []; + @override State createState() => _MyStatefulWidgetState(); } class _MyStatefulWidgetState extends State with TickerProviderStateMixin { - late TabController _tabController; + late TabController tabController; @override void initState() { super.initState(); - _tabController = TabController(length: 5, vsync: this); + tabController = TabController(length: 5, vsync: this); } @override void dispose() { - _tabController.dispose(); + tabController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { + var pass = EventListStorage("Project").readEvents().then((value) { + widget.eventList = value; + }); + var systemColor = MediaQuery.of(context).platformBrightness; bool darkMode = systemColor == Brightness.dark; Color labelColorChange; @@ -154,15 +162,6 @@ class _MyStatefulWidgetState extends State ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: () => onAddEventButtonPressed(), - child: const Icon( - Icons.add, - size: 45, - color: Colors.white, - ), - backgroundColor: Colors.blueGrey, - ), appBar: AppBar( title: Text( 'DayToDay', @@ -186,10 +185,10 @@ class _MyStatefulWidgetState extends State ),*/ ], bottom: TabBar( + isScrollable: true, indicatorColor: Colors.white, labelColor: Colors.white, - controller: _tabController, - isScrollable: true, + controller: tabController, indicatorSize: TabBarIndicatorSize.label, tabs: [ Tab( @@ -209,45 +208,35 @@ class _MyStatefulWidgetState extends State text: "To-Do", ), const Tab( - text: "Projects", + text: "Assignments", ), const Tab( - text: "Assignments", + text: "Projects", ), const Tab( text: "Exams", ), + ], ), ), body: TabBarView( - controller: _tabController, + controller: tabController, + children: [ CalendarWidget( stream: streamController.stream, ), const ToDoListDirectoryWidget(), - const Center( - child: Text("Projects"), - ), - const Center( - child: Text("HW"), - ), - const Center( - child: Text("Exams"), - ) + AssignmentsWidget(stream: streamController.stream,), + ProjectsWidget(stream: streamController.stream,), + ExamsWidget(stream: streamController.stream,), ], + ), ); } void onSearchButtonPressed() {} - void onAddEventButtonPressed() { - Navigator.of(context).push(MaterialPageRoute(builder: (context) { - int? clicked = StateWidget.of(context)?.clicked; - //print(clicked); - return const EventForm(); - })); - } } diff --git a/lib/projects.dart b/lib/projects.dart new file mode 100644 index 0000000..5137dc2 --- /dev/null +++ b/lib/projects.dart @@ -0,0 +1,4 @@ +class Project { + List projects = []; + List checked = []; +} diff --git a/lib/projects_widget.dart b/lib/projects_widget.dart new file mode 100644 index 0000000..fe19594 --- /dev/null +++ b/lib/projects_widget.dart @@ -0,0 +1,89 @@ +import 'dart:async'; +import 'package:day_to_day/globals.dart'; +import 'event_list_storage.dart'; +import 'event_form.dart'; +import 'package:flutter/material.dart'; +import 'events.dart'; +import 'globals.dart' as globals; +//import 'package:firebase_database/firebase_database.dart'; +StreamController streamController = StreamController.broadcast(); + +class ProjectsWidget extends StatefulWidget { + List projects = []; + ProjectsWidget({Key? key, required this.stream}) : super(key: key); + final Stream stream; + + @override + State createState() => ProjectsState(); +} + +class ProjectsState extends State { + + @override + void initState() { + + widget.stream.listen((event) { + setState(() { + + }); + }); + super.initState(); + } + @override + Widget build(BuildContext context) { + projects = []; + globals.eventsList.forEach((key, value) { + for (int i = 0; i < value.length; i++) { + if (value[i].type.contains("project")) { + projects.add(value[i]); + } + } + }); + print("\n\n\nProjects: " + projects.length.toString()); + return Scaffold( + appBar: AppBar( + title: const Center(child: Text("Projects List")), + backgroundColor: const Color.fromARGB(255, 255, 82, 82), + ), + body: ListView.builder( + itemCount: projects.length, + itemBuilder: (BuildContext context, int index) { + return Card( + child: CheckboxListTile( + dense: true, + activeColor: Colors.red[400], + controlAffinity: ListTileControlAffinity.leading, + value: false, + onChanged: (value) { + setState(() { + projects.removeAt(index); + }); + }, + title: Text( + projects[index].title, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Color.fromARGB(255, 12, 12, 12)), + ))); + }, + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + Navigator.of(context).push(MaterialPageRoute(builder: (context) { + return EventForm(); + })); + }); + setState(() {}); + }, + child: const Icon( + Icons.add, + size: 45, + color: Colors.white, + ), + backgroundColor: Colors.blueGrey, + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 1496fc3..f282d7c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,13 +57,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" + firebase_auth: + dependency: "direct main" + description: + name: firebase_auth + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.14" + firebase_auth_platform_interface: + dependency: transitive + description: + name: firebase_auth_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "6.2.3" + firebase_auth_web: + dependency: transitive + description: + name: firebase_auth_web + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.12" firebase_core: dependency: "direct main" description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.14.0" + version: "1.14.1" firebase_core_platform_interface: dependency: transitive description: @@ -77,28 +112,28 @@ packages: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "1.6.1" + version: "1.6.2" firebase_database: dependency: "direct main" description: name: firebase_database url: "https://pub.dartlang.org" source: hosted - version: "9.0.9" + version: "9.0.11" firebase_database_platform_interface: dependency: transitive description: name: firebase_database_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "0.2.1+2" + version: "0.2.1+3" firebase_database_web: dependency: transitive description: name: firebase_database_web url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+8" + version: "0.2.0+10" flutter: dependency: "direct main" description: flutter @@ -121,6 +156,20 @@ packages: description: flutter source: sdk version: "0.0.0" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" js: dependency: transitive description: @@ -163,6 +212,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_provider: + dependency: "direct main" + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.9" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" plugin_platform_interface: dependency: transitive description: @@ -170,6 +275,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" sky_engine: dependency: transitive description: flutter @@ -231,6 +343,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.5.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+1" sdks: dart: ">=2.16.1 <3.0.0" - flutter: ">=1.20.0" + flutter: ">=2.8.0" diff --git a/pubspec.yaml b/pubspec.yaml index cf055c1..d091755 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,15 +31,20 @@ dependencies: sdk: flutter firebase_core: ^1.13.1 firebase_database: ^9.0.8 + path_provider: ^2.0.9 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + firebase_auth: ^3.3.14 dev_dependencies: flutter_test: sdk: flutter + flutter_launcher_icons: ^0.9.2 + flutter_native_splash: ^2.1.6 + # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your @@ -47,6 +52,19 @@ dev_dependencies: # rules and activating additional ones. flutter_lints: ^1.0.0 +flutter_icons: + android: "launcher_icon" + ios: true + image_path: "assets/icons/dtdLogo1.png" + +flutter_native_splash: + color: "#de6749" + image: "assets/icons/dtdLogo1.png" + android12: + image: "assets/icons/dtdLogo1.png" + android: true + ios: true + # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec @@ -65,6 +83,9 @@ flutter: - assets/icons/search-icon.png - assets/icons/clock.png - assets/icons/repeat.png + - assets/icons/dayToDayLogo.jpg + - assets/icons/dtdLogo2.jpg + - assets/icons/dtdLogo1.png # An image asset can refer to one or more resolution-specific "variants", see diff --git a/test/calendar_widget_test.dart b/test/calendar_widget_test.dart index 450d0ca..5b31b3c 100644 --- a/test/calendar_widget_test.dart +++ b/test/calendar_widget_test.dart @@ -27,7 +27,7 @@ void main() { expect(find.text('2022'), findsOneWidget); }); testWidgets('Test if add event button brings up new page', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp(home: Material(child: AppWidget()))); + //await tester.pumpWidget(const MaterialApp(home: Material(child: AppWidget()))); await tester.tap(find.byType(FloatingActionButton)); await tester.pumpAndSettle(); @@ -35,7 +35,7 @@ void main() { expect(find.text('All Day'), findsOneWidget); }); testWidgets('Test if cancel button on event add page goes back to calendar', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp(home: Material(child: AppWidget()))); + //await tester.pumpWidget(const MaterialApp(home: Material(child: AppWidget()))); await tester.tap(find.byType(FloatingActionButton)); await tester.pumpAndSettle(); await tester.tap(find.byType(TextButton).first);