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
38 changes: 38 additions & 0 deletions lib/animations/fade_in.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';

class FadeIn extends StatelessWidget {
final double delay;
final Widget child;
const FadeIn({Key? key, required this.child, required this.delay})
: super(key: key);

TimelineTween<Prop> createTween() {
var tween = TimelineTween<Prop>();
var scene = tween.addScene(
duration: const Duration(milliseconds: 400), begin: Duration.zero);
scene.animate(Prop.translateX,
tween: Tween<double>(begin: 130.0, end: 0.0), curve: Curves.easeOut);
scene.animate(Prop.opacity, tween: Tween<double>(begin: 0.0, end: 1.0));
return tween;
}

@override
Widget build(BuildContext context) {
final tween = createTween();
return PlayAnimation<TimelineValue<Prop>>(
delay: Duration(milliseconds: (200 * delay).round()),
duration: tween.duration,
builder: ((context, child, value) {
return Opacity(
opacity: value.get(Prop.opacity),
child: Transform.translate(
offset: Offset(value.get(Prop.translateX), 0),
child: child,
),
);
}),
tween: tween,
child: child);
}
}
19 changes: 19 additions & 0 deletions lib/config/get_it_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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<Dio>(Dio());
registerSingleton<TodoRepository>(TodoRepositoryImpl());
registerSingleton<FetchTodos>(FetchTodos());
registerSingleton<NewTodo>(NewTodo());
registerSingleton<DoneTodo>(DoneTodo());
registerSingleton<RemoveDoneTodos>(RemoveDoneTodos());
}
}
39 changes: 39 additions & 0 deletions lib/cubit/todo_list_states.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:todo_app/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;
}
*/
@freezed
class TodoListState with _$TodoListState {
const factory TodoListState.initial(
{required List<Todo> todos, required bool succes}) = Initial;
const factory TodoListState.loaded(
{required List<Todo> todos, required bool succes}) = Loaded;
const factory TodoListState.fail(
{required List<Todo> todos,
required bool succes,
required String error}) = Fail;
}
Loading