Skip to content

Commit

Permalink
finished the categories local nosql database
Browse files Browse the repository at this point in the history
  • Loading branch information
Kind-Unes committed Feb 8, 2024
1 parent 8509751 commit 88ac716
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 390 deletions.
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:habit_now/src/cubit/main/bottomNavBar_cubit.dart';
import 'package:habit_now/src/cubit/tasks_cubits/DefineTaskFocusNode_cubit.dart';
import 'package:habit_now/src/cubit/tasks_cubits/DefineTaskTextController_cubit.dart';
import 'package:habit_now/src/cubit/tasks_cubits/addCategory_cubiy.dart';
import 'package:habit_now/src/cubit/tasks_cubits/categories_database_cubit.dart';
import 'package:habit_now/src/cubit/tasks_cubits/database_service_cubit.dart';
import 'package:habit_now/src/cubit/tasks_cubits/new_task_cubit.dart';
Expand Down Expand Up @@ -37,11 +38,11 @@ void main() async {
Hive.registerAdapter(CategoryModelAdapter());
Hive.registerAdapter(ColorAdapter());
Hive.registerAdapter(TimeOfDayAdapter());
Hive.registerAdapter(IconDataAdapter()); // Register the adapter for IconData
Hive.registerAdapter(TaskModelAdapter());
Hive.registerAdapter(IconDataAdapter());

await Hive.initFlutter();
tasksBox = await Hive.openBox<TaskModel>('dingo');
tasksBox = await Hive.openBox<TaskModel>('tasks');
customCategories = await Hive.openBox<CategoryModel>("categories");

runApp(const MyApp());
Expand Down Expand Up @@ -87,6 +88,9 @@ class MyApp extends StatelessWidget {
BlocProvider(
create: (context) => CategoriesDatabaseCubit(),
),
BlocProvider(
create: (context) => NewCategoryCubit(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down
67 changes: 67 additions & 0 deletions lib/src/cubit/tasks_cubits/addCategory_cubiy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:habit_now/src/utils/const.dart';
import 'package:habit_now/src/utils/models/task_model.dart';
import 'package:uuid/uuid.dart';

class NewCategoryState extends Equatable {
final CategoryModel categoryModel;

const NewCategoryState(this.categoryModel);

@override
List<Object?> get props => [categoryModel];
}

class NewCategoryCubit extends Cubit<NewCategoryState> {
NewCategoryCubit()
: super(NewCategoryState(CategoryModel(
color: AppColors.kLightPurple,
icon: Icons.category,
id: const Uuid().v4(),
name: 'New category')));

void updateProperty(
{String? name,
String? id,
IconData? icon,
Color? color,
bool? isPendingTask}) {
final CategoryModel updatedTaskModel = CategoryModel(
name: name ?? state.categoryModel.name,
id: id ?? state.categoryModel.id,
color: color ?? state.categoryModel.color,
icon: icon ?? state.categoryModel.icon,
);
emit(NewCategoryState(updatedTaskModel));
}

void initState() {
emit(NewCategoryState(CategoryModel(
color: AppColors.kLightPurple,
icon: Icons.category,
id: const Uuid().v4(),
name: 'New category')));
}
//! implement more if needed
}

// class EditTaskControllerCubit extends Cubit<void Function()> {
// EditTaskControllerCubit() : super(() {});
// final TextEditingController controller = TextEditingController();
// final FocusNode focusNode = FocusNode();

// void initializeTextField(String text) {
// // Set the initial text and highlight it
// controller.text = text;
// controller.selection = TextSelection(
// baseOffset: 0,
// extentOffset: controller.text.length,
// );

// // Request focus to automatically highlight the text
// focusNode.requestFocus();
// emit(() {});
// }
// }
8 changes: 6 additions & 2 deletions lib/src/cubit/tasks_cubits/new_task_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class NewTaskCubit extends Cubit<NewTaskState> {
category: CategoryModel(
color: AppColors.kLightPurple,
name: "Task",
icon: Icons.timer_outlined),
icon: Icons.timer_outlined,
id: '3'),
date: DateTime.now(),
reminder: ReminderModel(
schedule: ReminderSchedule.alwaysEnabled,
Expand Down Expand Up @@ -59,7 +60,10 @@ class NewTaskCubit extends Cubit<NewTaskState> {
emit(NewTaskState(TaskModel(
name: '',
category: CategoryModel(
color: AppColors.kLightPurple, name: "Task", icon: Icons.abc),
color: AppColors.kLightPurple,
name: "Task",
icon: Icons.abc,
id: ''), // TODO: Don't forget to set this later in the state managemnet part
date: DateTime.now(),
reminder: ReminderModel(
schedule: ReminderSchedule.alwaysEnabled,
Expand Down
32 changes: 19 additions & 13 deletions lib/src/presentation/shared/bottomSheets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:habit_now/src/cubit/tasks_cubits/addCategory_cubiy.dart';
import 'package:habit_now/src/cubit/tasks_cubits/categories_database_cubit.dart';
import 'package:habit_now/src/presentation/shared/dialogMessages.dart';
import 'package:habit_now/src/presentation/tasks/subpages/newCategory_page.dart';
import 'package:habit_now/src/presentation/timer/components/timer_widgets.dart';
import 'package:habit_now/src/utils/boxes.dart';
import 'package:habit_now/src/utils/const.dart';
import 'package:habit_now/src/utils/extentions.dart';
import 'package:habit_now/src/utils/models/task_model.dart';
Expand Down Expand Up @@ -62,7 +66,8 @@ class NewCategoryBottomSheetTile extends StatelessWidget {

class NewCategoryBottomSheetTileButton extends StatelessWidget {
const NewCategoryBottomSheetTileButton({
super.key, required this.categoryModel,
super.key,
required this.categoryModel,
});

final CategoryModel categoryModel;
Expand All @@ -73,14 +78,15 @@ class NewCategoryBottomSheetTileButton extends StatelessWidget {
color: AppColors.kBackgroundColor,
child: InkWell(
onTap: () {


// add to data base
// + you should refresh the main page and implement a refreshing function or getCategories function
// re initialize the NEWCATEGORY CUBIT + CREATE IT FIRST
// WRAP
// ADD TO UI STUFF
// POP
context.read<CategoriesDatabaseCubit>().createCategory(
context.read<NewCategoryCubit>().state.categoryModel);
// get data list
context.read<CategoriesDatabaseCubit>().getTasks();
//pop
context.pop();

print(customCategories.values.length);
},
child: Container(
decoration: const BoxDecoration(
Expand Down Expand Up @@ -146,7 +152,7 @@ class NewCategoryBottomSheetFirstTile extends StatelessWidget {
color: category.color,
borderRadius: BorderRadius.circular(context.height * 0.015)),
child: Icon(
Icons.category,
category.icon,
size: context.fontSize * 1.5,
),
),
Expand Down Expand Up @@ -261,9 +267,7 @@ class NewCategoryBottomSheet extends StatelessWidget {
icon: Icons.mode_edit_outline_outlined,
title: 'Category name',
function: () {
context.showDialogMessage(const TextDialog(
label: 'Category',
));
context.showDialogMessage(const CategoryTextDialog());
},
),
NewCategoryBottomSheetTile(
Expand All @@ -280,7 +284,9 @@ class NewCategoryBottomSheet extends StatelessWidget {
context.showDialogMessage(const NewCategoryColorDialog());
},
),
const NewCategoryBottomSheetTileButton()
NewCategoryBottomSheetTileButton(
categoryModel: category,
)
],
);
}
Expand Down
Loading

0 comments on commit 88ac716

Please sign in to comment.