diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 596ef66..3accc99 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -9,8 +9,8 @@ import 'package:app/data/repositories/tasks_repository.dart'; import 'package:app/data/sources/local/tasks_storage.dart'; import 'package:app/data/sources/remote/tasks_api.dart'; import 'package:app/domain/bloc/bloc_dispatcher.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/domain/entities/task.dart'; import 'package:app/main.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; diff --git a/lib/core/di/dependency_container.dart b/lib/core/di/dependency_container.dart index acd6c96..39573c7 100644 --- a/lib/core/di/dependency_container.dart +++ b/lib/core/di/dependency_container.dart @@ -11,8 +11,8 @@ import 'package:app/data/repositories/tasks_repository.dart'; import 'package:app/data/sources/local/tasks_storage.dart'; import 'package:app/data/sources/remote/tasks_api.dart'; import 'package:app/domain/bloc/bloc_dispatcher.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/firebase_options.dart'; import 'package:dio/dio.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; diff --git a/lib/domain/bloc/bloc_dispatcher.dart b/lib/domain/bloc/bloc_dispatcher.dart index 2d4c12a..dc961b9 100644 --- a/lib/domain/bloc/bloc_dispatcher.dart +++ b/lib/domain/bloc/bloc_dispatcher.dart @@ -4,8 +4,8 @@ import 'package:app/core/constants.dart'; import 'package:app/core/services/network_status.dart'; import 'package:app/core/services/sync_storage.dart'; import 'package:app/data/repositories/tasks_repository.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/domain/entities/task.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; diff --git a/lib/domain/bloc/sync_bloc.dart b/lib/domain/bloc/sync_bloc/sync_bloc.dart similarity index 100% rename from lib/domain/bloc/sync_bloc.dart rename to lib/domain/bloc/sync_bloc/sync_bloc.dart diff --git a/lib/domain/bloc/sync_event.dart b/lib/domain/bloc/sync_bloc/sync_event.dart similarity index 100% rename from lib/domain/bloc/sync_event.dart rename to lib/domain/bloc/sync_bloc/sync_event.dart diff --git a/lib/domain/bloc/sync_state.dart b/lib/domain/bloc/sync_bloc/sync_state.dart similarity index 100% rename from lib/domain/bloc/sync_state.dart rename to lib/domain/bloc/sync_bloc/sync_state.dart diff --git a/lib/domain/bloc/tasks_cubit.dart b/lib/domain/bloc/tasks_cubit/tasks_cubit.dart similarity index 61% rename from lib/domain/bloc/tasks_cubit.dart rename to lib/domain/bloc/tasks_cubit/tasks_cubit.dart index f1ff3f8..cd252b3 100644 --- a/lib/domain/bloc/tasks_cubit.dart +++ b/lib/domain/bloc/tasks_cubit/tasks_cubit.dart @@ -3,6 +3,8 @@ import 'package:app/domain/entities/task.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +part 'tasks_state.dart'; + class TasksCubit extends Cubit { final SettingsStorage settingsStorage; @@ -42,36 +44,3 @@ class TasksCubit extends Cubit { emit(state.copyWith(showDoneTasks: newShowDoneTasks)); } } - -final class TasksState extends Equatable { - final List tasks; - final bool showDoneTasks; - final bool isInitialized; - - const TasksState( - this.tasks, { - required this.showDoneTasks, - this.isInitialized = false, - }); - - List get tasksToDisplay => - showDoneTasks ? tasks : tasks.where((task) => !task.isDone).toList(); - - int get doneTaskCount => - tasks.fold(0, (acc, task) => acc + (task.isDone ? 1 : 0)); - - TasksState copyWith({ - List? tasks, - bool? showDoneTasks, - bool? isInitialized, - }) { - return TasksState( - tasks ?? this.tasks, - showDoneTasks: showDoneTasks ?? this.showDoneTasks, - isInitialized: isInitialized ?? this.isInitialized, - ); - } - - @override - List get props => [tasks, showDoneTasks, isInitialized]; -} diff --git a/lib/domain/bloc/tasks_cubit/tasks_state.dart b/lib/domain/bloc/tasks_cubit/tasks_state.dart new file mode 100644 index 0000000..8c99194 --- /dev/null +++ b/lib/domain/bloc/tasks_cubit/tasks_state.dart @@ -0,0 +1,34 @@ +part of 'tasks_cubit.dart'; + +final class TasksState extends Equatable { + final List tasks; + final bool showDoneTasks; + final bool isInitialized; + + const TasksState( + this.tasks, { + required this.showDoneTasks, + this.isInitialized = false, + }); + + List get tasksToDisplay => + showDoneTasks ? tasks : tasks.where((task) => !task.isDone).toList(); + + int get doneTaskCount => + tasks.fold(0, (acc, task) => acc + (task.isDone ? 1 : 0)); + + TasksState copyWith({ + List? tasks, + bool? showDoneTasks, + bool? isInitialized, + }) { + return TasksState( + tasks ?? this.tasks, + showDoneTasks: showDoneTasks ?? this.showDoneTasks, + isInitialized: isInitialized ?? this.isInitialized, + ); + } + + @override + List get props => [tasks, showDoneTasks, isInitialized]; +} diff --git a/lib/presentation/screens/home_screen/home_screen.dart b/lib/presentation/screens/home_screen/home_screen.dart index 86884e5..188ff3e 100644 --- a/lib/presentation/screens/home_screen/home_screen.dart +++ b/lib/presentation/screens/home_screen/home_screen.dart @@ -3,8 +3,8 @@ import 'package:app/core/di/dependency_container.dart'; import 'package:app/core/services/device_info_service.dart'; import 'package:app/core/services/network_status.dart'; import 'package:app/domain/bloc/bloc_dispatcher.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/core/extensions/l10n.dart'; import 'package:app/presentation/screens/home_screen/widgets/tasks_visibility_button.dart'; import 'package:app/presentation/screens/home_screen/widgets/header.dart'; diff --git a/lib/presentation/screens/home_screen/widgets/header.dart b/lib/presentation/screens/home_screen/widgets/header.dart index 09cd8c9..5b7f8dd 100644 --- a/lib/presentation/screens/home_screen/widgets/header.dart +++ b/lib/presentation/screens/home_screen/widgets/header.dart @@ -1,6 +1,6 @@ import 'package:app/core/env_config.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/core/extensions/l10n.dart'; import 'package:app/presentation/screens/home_screen/home_screen.dart'; import 'package:app/presentation/screens/home_screen/widgets/tasks_visibility_button.dart'; diff --git a/lib/presentation/screens/home_screen/widgets/tasks_visibility_button.dart b/lib/presentation/screens/home_screen/widgets/tasks_visibility_button.dart index 41398ec..19d29d2 100644 --- a/lib/presentation/screens/home_screen/widgets/tasks_visibility_button.dart +++ b/lib/presentation/screens/home_screen/widgets/tasks_visibility_button.dart @@ -1,5 +1,5 @@ import 'package:app/core/constants.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/presentation/screens/home_screen/home_screen.dart'; import 'package:app/core/extensions/app_theme.dart'; import 'package:flutter/material.dart'; diff --git a/test/domain/bloc/sync_bloc_test.dart b/test/domain/bloc/sync_bloc_test.dart index b72bd7e..30721cf 100644 --- a/test/domain/bloc/sync_bloc_test.dart +++ b/test/domain/bloc/sync_bloc_test.dart @@ -1,5 +1,5 @@ import 'package:app/data/repositories/tasks_repository.dart'; -import 'package:app/domain/bloc/sync_bloc.dart'; +import 'package:app/domain/bloc/sync_bloc/sync_bloc.dart'; import 'package:app/domain/entities/task.dart'; import 'package:bloc_test/bloc_test.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/domain/bloc/tasks_cubit_test.dart b/test/domain/bloc/tasks_cubit_test.dart index 7364a53..92bc4a6 100644 --- a/test/domain/bloc/tasks_cubit_test.dart +++ b/test/domain/bloc/tasks_cubit_test.dart @@ -1,5 +1,5 @@ import 'package:app/core/services/settings_storage.dart'; -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:bloc_test/bloc_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; diff --git a/test/domain/bloc/test_data.dart b/test/domain/bloc/test_data.dart index bd12a83..6f9976a 100644 --- a/test/domain/bloc/test_data.dart +++ b/test/domain/bloc/test_data.dart @@ -1,4 +1,4 @@ -import 'package:app/domain/bloc/tasks_cubit.dart'; +import 'package:app/domain/bloc/tasks_cubit/tasks_cubit.dart'; import 'package:app/domain/entities/task.dart'; const deviceId = 'device1';