Skip to content

Commit

Permalink
Move bloc files into own directory
Browse files Browse the repository at this point in the history
  • Loading branch information
eshfield committed Jul 17, 2024
1 parent 88d1abb commit 3484e5c
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 47 deletions.
4 changes: 2 additions & 2 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions lib/core/di/dependency_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/bloc/bloc_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TasksState> {
final SettingsStorage settingsStorage;

Expand Down Expand Up @@ -42,36 +44,3 @@ class TasksCubit extends Cubit<TasksState> {
emit(state.copyWith(showDoneTasks: newShowDoneTasks));
}
}

final class TasksState extends Equatable {
final List<Task> tasks;
final bool showDoneTasks;
final bool isInitialized;

const TasksState(
this.tasks, {
required this.showDoneTasks,
this.isInitialized = false,
});

List<Task> 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<Task>? tasks,
bool? showDoneTasks,
bool? isInitialized,
}) {
return TasksState(
tasks ?? this.tasks,
showDoneTasks: showDoneTasks ?? this.showDoneTasks,
isInitialized: isInitialized ?? this.isInitialized,
);
}

@override
List<Object?> get props => [tasks, showDoneTasks, isInitialized];
}
34 changes: 34 additions & 0 deletions lib/domain/bloc/tasks_cubit/tasks_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
part of 'tasks_cubit.dart';

final class TasksState extends Equatable {
final List<Task> tasks;
final bool showDoneTasks;
final bool isInitialized;

const TasksState(
this.tasks, {
required this.showDoneTasks,
this.isInitialized = false,
});

List<Task> 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<Task>? tasks,
bool? showDoneTasks,
bool? isInitialized,
}) {
return TasksState(
tasks ?? this.tasks,
showDoneTasks: showDoneTasks ?? this.showDoneTasks,
isInitialized: isInitialized ?? this.isInitialized,
);
}

@override
List<Object?> get props => [tasks, showDoneTasks, isInitialized];
}
4 changes: 2 additions & 2 deletions lib/presentation/screens/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/screens/home_screen/widgets/header.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/domain/bloc/sync_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/domain/bloc/tasks_cubit_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/domain/bloc/test_data.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 3484e5c

Please sign in to comment.