Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add networking #5

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions lib/config/get_it_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';
import 'package:todo_app/repositories/todo_repository.dart';
import 'package:todo_app/repositories/todo_repository_interface.dart';
import 'package:todo_app/use_cases/done_todo.dart';
import 'package:todo_app/use_cases/fetch_todos.dart';
import 'package:todo_app/use_cases/new_todo.dart';
import 'package:todo_app/use_cases/remove_done_todos.dart';

extension GetItConfig on GetIt {
void init() {
registerSingleton<ITodoRepository>(TodoRepository(Dio()));
fedecor9 marked this conversation as resolved.
Show resolved Hide resolved
registerSingleton<FetchTodos>(FetchTodos());
registerSingleton<NewTodo>(NewTodo());
registerSingleton<DoneTodo>(DoneTodo());
registerSingleton<RemoveDoneTodos>(RemoveDoneTodos());
}
}
26 changes: 26 additions & 0 deletions lib/cubit/todo_list_states.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../models/todo.dart';
part 'todo_list_states.freezed.dart';

@immutable
abstract class TodoListState {
List<Todo> get todos => [];
}

@freezed
class TodoListInitialState extends TodoListState with _$TodoListInitialState {
factory TodoListInitialState({required final List<Todo> todos}) =
_TodoListInitialState;
}

@unfreezed
class TodoListLoadedState extends TodoListState with _$TodoListLoadedState {
factory TodoListLoadedState({required List<Todo> todos}) =
_TodoListLoadedState;
}

@unfreezed
class TodoListFailState extends TodoListState with _$TodoListFailState {
factory TodoListFailState(
{required List<Todo> todos, required String error}) = _TodoListFailState;
}
fedecor9 marked this conversation as resolved.
Show resolved Hide resolved
Loading