Skip to content

Commit

Permalink
Merge pull request #5 from FabianVarela/navigator2_riverpod_freezed
Browse files Browse the repository at this point in the history
Navigator 2.0 with riverpod and freezed
  • Loading branch information
FabianVarela authored May 29, 2022
2 parents c0e6de2 + f0f119b commit 8bcb4f7
Show file tree
Hide file tree
Showing 11 changed files with 802 additions and 163 deletions.
8 changes: 4 additions & 4 deletions coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 5 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:crud_todo_app/common/adaptive_contextual_layout.dart';
import 'package:crud_todo_app/navigator/crud_todo_information_parser.dart';
import 'package:crud_todo_app/navigator/crud_todo_router_delegate.dart';
import 'package:crud_todo_app/provider_dependency.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
Expand All @@ -19,19 +18,14 @@ Future<void> main() async {
runApp(const ProviderScope(child: TodoListApp()));
}

class TodoListApp extends StatefulWidget {
class TodoListApp extends ConsumerWidget {
const TodoListApp({Key? key}) : super(key: key);

@override
_TodoListAppState createState() => _TodoListAppState();
}

class _TodoListAppState extends State<TodoListApp> {
final _todoRouterDelegate = CrudTodoRouterDelegate();
final _todoInfoParser = CrudTodoInformationParser();
Widget build(BuildContext context, WidgetRef ref) {
final _todoRouterDelegate = ref.watch(crudTodoRouterDelegateProvider);
final _todoInfoParser = ref.watch(crudTodoInformationParserProvider);

@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: ThemeData(
Expand Down
88 changes: 12 additions & 76 deletions lib/navigator/config/crud_todo_config.dart
Original file line number Diff line number Diff line change
@@ -1,83 +1,19 @@
import 'package:equatable/equatable.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

class CrudTodoConfig extends Equatable {
const CrudTodoConfig.categoryList()
: currentCategoryId = null,
currentTodoId = null,
isTodoNew = false,
isTodoUpdate = false,
isUnknown = false;
part 'crud_todo_config.freezed.dart';

const CrudTodoConfig.todoList({String? categoryId})
: currentCategoryId = categoryId,
currentTodoId = null,
isTodoNew = false,
isTodoUpdate = false,
isUnknown = false;
@freezed
class CrudTodoConfig with _$CrudTodoConfig {
const factory CrudTodoConfig.categoryList() = CrudTodoConfigCategoryList;

const CrudTodoConfig.addTodo({String? categoryId})
: currentCategoryId = categoryId,
currentTodoId = null,
isTodoNew = true,
isTodoUpdate = false,
isUnknown = false;
const factory CrudTodoConfig.todoList(String categoryId) =
CrudTodoConfigTodoList;

const CrudTodoConfig.updateTodo({String? categoryId, String? todoId})
: currentCategoryId = categoryId,
currentTodoId = todoId,
isTodoNew = false,
isTodoUpdate = true,
isUnknown = false;
const factory CrudTodoConfig.addTodo(String categoryId) =
CrudTodoConfigAddTodo;

const CrudTodoConfig.unknown()
: currentCategoryId = null,
currentTodoId = null,
isTodoNew = false,
isTodoUpdate = false,
isUnknown = true;
const factory CrudTodoConfig.updateTodo(String categoryId, String todoId) =
CrudTodoConfigUpdateTodo;

final String? currentCategoryId;
final String? currentTodoId;
final bool isTodoNew;
final bool isTodoUpdate;
final bool isUnknown;

bool get isPageUnknown => isUnknown;

bool get isCategoryListPage =>
currentCategoryId == null &&
currentTodoId == null &&
!isTodoNew &&
!isTodoUpdate &&
!isUnknown;

bool get isTodoListPage =>
currentCategoryId != null &&
currentTodoId == null &&
!isTodoNew &&
!isTodoUpdate &&
!isUnknown;

bool get isAddTodoPage =>
currentCategoryId != null &&
currentTodoId == null &&
isTodoNew &&
!isTodoUpdate &&
!isUnknown;

bool get isUpdateTodoPage =>
currentCategoryId != null &&
currentTodoId != null &&
!isTodoNew &&
isTodoUpdate &&
!isUnknown;

@override
List<Object?> get props => [
currentCategoryId,
currentTodoId,
isTodoNew,
isTodoUpdate,
isUnknown,
];
const factory CrudTodoConfig.unknown() = CrudTodoConfigUnknown;
}
Loading

0 comments on commit 8bcb4f7

Please sign in to comment.