Skip to content

Commit

Permalink
new design and task form
Browse files Browse the repository at this point in the history
  • Loading branch information
Alidantech committed May 26, 2024
1 parent 2e7ad97 commit f321288
Show file tree
Hide file tree
Showing 66 changed files with 1,966 additions and 2,850 deletions.
18 changes: 9 additions & 9 deletions lib/config/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import 'package:flutter/material.dart';

class AppColors {
// dark theme colors
static const Color primaryDark = Colors.green;
static Color primaryDark500 = Colors.green.shade500;
static Color primaryDark800 = Colors.green.shade800;
static const Color primaryDark = Colors.purple;
static Color primaryDark500 = Colors.purple.shade500;
static Color primaryDark800 = Colors.purple.shade800;
static const Color backgroundDark = Colors.black;
static Color scaffoldBackgroundDark = Colors.grey.shade900;
static Color scaffoldBackgroundDark = Color.fromARGB(255, 7, 8, 12);
static const Color cardDark = Colors.black12;
static const Color shadowDark = Colors.black;
static const Color drawerBackgroundDark = Colors.black87;
static const Color dialogBackgroundDark = Colors.grey;

// light colors
static const Color primaryLight = Colors.green;
static Color primaryLight400 = Colors.green.shade400;
static Color primaryLight50 = Colors.green.shade50;
static const Color primaryLight = Colors.purple;
static Color primaryLight400 = Colors.purple.shade400;
static Color primaryLight50 = Colors.purple.shade50;
static const Color backgroundLight = Colors.white;
static const Color scaffoldBackgroundLight = Colors.white;
static Color cardLight = Colors.grey.shade200;
static Color shadowLight = Colors.grey.shade200;
static Color drawerBackgroundLight = Colors.green.shade50;
static Color dialogBackgroundLight = Colors.green.shade50;
static Color drawerBackgroundLight = Colors.purple.shade50;
static Color dialogBackgroundLight = Colors.purple.shade50;
}
1 change: 1 addition & 0 deletions lib/controllers/auth/signup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SignUpController {
final FirebaseAuth _auth = FirebaseAuth.instance;
final ValueNotifier<bool> isLoading = ValueNotifier<bool>(false);


Future<Either<String, User?>> signUp(
BuildContext context, String email, String password) async {
try {
Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/common/event_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:Organiser/models/common/event_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class EventsController {
class EventController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;

EventsController(this._parentCollection);
EventController(this._parentCollection);

Future<void> addEvent(String documentId, Event event) async {
try {
Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/common/goal_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:Organiser/models/common/goal_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class GoalsController {
class GoalController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;

GoalsController(this._parentCollection);
GoalController(this._parentCollection);

Future<void> addGoal(String documentId, Goal goal) async {
try {
Expand Down
37 changes: 19 additions & 18 deletions lib/controllers/common/task_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import 'package:cloud_firestore/cloud_firestore.dart';

class TaskController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;
final String parentCollection;
final String ownerId;

TaskController(this._parentCollection);
TaskController(this.parentCollection, this.ownerId);

Future<void> addTask(String documentId, Task task) async {
Future<void> addTask(Task task) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection(parentCollection)
.doc(ownerId)
.collection('tasks')
.add(task.toMap());
} catch (e) {
Expand All @@ -20,25 +21,25 @@ class TaskController {
}
}

Future<void> updateTask(String documentId, Task task) async {
Future<void> updateTask(Task task) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection(parentCollection)
.doc(ownerId)
.collection('tasks')
.doc(task.id)
.set(task.toMap());
} catch (e) {
print('Error updating task: $e');
rethrow;
rethrow;
}
}

Future<void> deleteTask(String documentId, String taskId) async {
Future<void> deleteTask(String taskId) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection(parentCollection)
.doc(ownerId)
.collection('tasks')
.doc(taskId)
.delete();
Expand All @@ -48,22 +49,22 @@ class TaskController {
}
}

Stream<List<Task>> getAllTasks(String documentId) {
Stream<List<Task>> getAllTasks() {
return _firestore
.collection(_parentCollection)
.doc(documentId)
.collection(parentCollection)
.doc(ownerId)
.collection('tasks')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Task.fromMap(doc.data(), doc.id))
.toList());
}

Future<Task?> getTaskById(String documentId, String taskId) async {
Future<Task?> getTaskById(String taskId) async {
try {
var docSnapshot = await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection(parentCollection)
.doc(ownerId)
.collection('tasks')
.doc(taskId)
.get();
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class UserController {
Future<void> deleteUser(String userId) async {
await _firestore.collection('users').doc(userId).delete();
}
}
}
10 changes: 4 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:Organiser/firebase_options.dart';
import 'package:Organiser/views/pages/splash.dart';
import 'package:Organiser/views/pages/splash.dart';
import 'package:Organiser/views/services/theme_provider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'views/services/user_provider.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -49,10 +49,7 @@ class _OrganiserAppState extends State<OrganiserApp> {
themeProvider.themeData.brightness == Brightness.dark
? Brightness.light
: Brightness.dark,
systemNavigationBarColor:
themeProvider.themeData.brightness == Brightness.dark
? Colors.black
: Colors.white,
systemNavigationBarColor: themeProvider.themeData.scaffoldBackgroundColor,
statusBarIconBrightness:
themeProvider.themeData.brightness == Brightness.dark
? Brightness.light
Expand All @@ -61,6 +58,7 @@ class _OrganiserAppState extends State<OrganiserApp> {
? Brightness.light
: Brightness.dark,
systemStatusBarContrastEnforced: false,
systemNavigationBarDividerColor: themeProvider.themeData.scaffoldBackgroundColor,
));
return MaterialApp(
theme: themeProvider.themeData,
Expand Down
107 changes: 107 additions & 0 deletions lib/models/classes/do_day.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import 'package:Organiser/models/enums/time_enums.dart';

class DoDay {
DateTime? tangibleValue;

DoDay({this.tangibleValue});

factory DoDay.fromEnum(DoDayEnum day, {DayOfWeek? dayName}) {
switch (day) {
case DoDayEnum.today:
return DoDay(tangibleValue: DateTime.now());
case DoDayEnum.tomorrow:
return DoDay(tangibleValue: DateTime.now().add(Duration(days: 1)));
case DoDayEnum.weekDay:
if (dayName != null) {
return DoDay(tangibleValue: getDateForDay(dayName));
}
return DoDay();
default:
return DoDay();
}
}

dynamic getEnumValue() {
return tangibleValue;
}

dynamic getTangibleValue() {
return tangibleValue;
}

void setCustomValue(dynamic value) {
if (value is DateTime) {
tangibleValue = value;
} else {
tangibleValue = null;
}
}

static DateTime getDateForDay(DayOfWeek dayName) {
final int targetDayIndex = dayName.index + 1;
final DateTime now = DateTime.now();
final int currentDayIndex = now.weekday;
final int daysDifference = (targetDayIndex - currentDayIndex + 7) % 7;
final DateTime targetDate = now.add(Duration(days: daysDifference));
return targetDate;
}

static String formatDate(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
}

String toText() {
if (tangibleValue == null) {
return 'No date set';
}

DateTime now = DateTime.now();
DateTime today = DateTime(now.year, now.month, now.day);
DateTime targetDate = DateTime(tangibleValue!.year, tangibleValue!.month, tangibleValue!.day);

if (targetDate == today) {
return 'Today';
} else if (targetDate == today.add(Duration(days: 1))) {
return 'Tomorrow';
} else if (targetDate == today.subtract(Duration(days: 1))) {
return 'Yesterday';
} else if (targetDate.isAfter(today.subtract(Duration(days: 7))) && targetDate.isBefore(today)) {
return 'Last ${dayOfWeek(targetDate.weekday)}';
} else if (targetDate.isAfter(today) && targetDate.isBefore(today.add(Duration(days: 7)))) {
return 'This ${dayOfWeek(targetDate.weekday)}';
} else if (targetDate.isAfter(today.add(Duration(days: 7))) && targetDate.isBefore(today.add(Duration(days: 14)))) {
return 'Next ${dayOfWeek(targetDate.weekday)}';
} else if (targetDate.month == now.month + 1 && targetDate.year == now.year) {
return 'Next month';
} else if (targetDate.year == now.year + 1) {
return 'Next year';
} else if (targetDate.month == now.month - 1 && targetDate.year == now.year) {
return 'Last month';
} else if (targetDate.year == now.year - 1) {
return 'Last year';
} else {
return 'On ${formatDate(tangibleValue!)}';
}
}

String dayOfWeek(int weekday) {
switch (weekday) {
case DateTime.monday:
return 'Monday';
case DateTime.tuesday:
return 'Tuesday';
case DateTime.wednesday:
return 'Wednesday';
case DateTime.thursday:
return 'Thursday';
case DateTime.friday:
return 'Friday';
case DateTime.saturday:
return 'Saturday';
case DateTime.sunday:
return 'Sunday';
default:
return '';
}
}
}
63 changes: 63 additions & 0 deletions lib/models/classes/do_time.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:Organiser/models/enums/time_enums.dart';
import 'package:flutter/material.dart';

class DoTime {
TimeOfDay? tangibleValue;

DoTime({this.tangibleValue});

factory DoTime.fromEnum(DoTimeEnum time) {
switch (time) {
case DoTimeEnum.morning:
return DoTime(tangibleValue: TimeOfDay(hour: 8, minute: 0));
case DoTimeEnum.noon:
return DoTime(tangibleValue: TimeOfDay(hour: 12, minute: 0));
case DoTimeEnum.afternoon:
return DoTime(tangibleValue: TimeOfDay(hour: 14, minute: 0));
case DoTimeEnum.evening:
return DoTime(tangibleValue: TimeOfDay(hour: 19, minute: 0));
case DoTimeEnum.night:
return DoTime(tangibleValue: TimeOfDay(hour: 21, minute: 0));
case DoTimeEnum.midnight:
return DoTime(tangibleValue: TimeOfDay(hour: 0, minute: 0));
case DoTimeEnum.none:
return DoTime();
default:
return DoTime();
}
}

TimeOfDay? getEnumValue() {
return tangibleValue;
}

TimeOfDay? getTangibleValue() {
return tangibleValue;
}

void setCustomValue(TimeOfDay value) {
tangibleValue = value;
}

String toText(BuildContext context) {
if (tangibleValue == null) {
return 'No time set';
}

if (tangibleValue == TimeOfDay(hour: 8, minute: 0)) {
return 'Morning';
} else if (tangibleValue == TimeOfDay(hour: 12, minute: 0)) {
return 'Noon';
} else if (tangibleValue == TimeOfDay(hour: 14, minute: 0)) {
return 'Afternoon';
} else if (tangibleValue == TimeOfDay(hour: 19, minute: 0)) {
return 'Evening';
} else if (tangibleValue == TimeOfDay(hour: 21, minute: 0)) {
return 'Night';
} else if (tangibleValue == TimeOfDay(hour: 0, minute: 0)) {
return 'Midnight';
} else {
return 'At ${tangibleValue!.format(context)}';
}
}
}
Loading

0 comments on commit f321288

Please sign in to comment.