diff --git a/coverage_badge.svg b/coverage_badge.svg index db8bc59..9d3823a 100644 --- a/coverage_badge.svg +++ b/coverage_badge.svg @@ -6,13 +6,13 @@ - - + + coverage coverage - 91% - 91% + 79% + 79% diff --git a/lib/main.dart b/lib/main.dart index 757d2f9..305addf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; @@ -19,19 +18,14 @@ Future 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 { - 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( diff --git a/lib/navigator/config/crud_todo_config.dart b/lib/navigator/config/crud_todo_config.dart index 406279c..bc926cb 100644 --- a/lib/navigator/config/crud_todo_config.dart +++ b/lib/navigator/config/crud_todo_config.dart @@ -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 get props => [ - currentCategoryId, - currentTodoId, - isTodoNew, - isTodoUpdate, - isUnknown, - ]; + const factory CrudTodoConfig.unknown() = CrudTodoConfigUnknown; } diff --git a/lib/navigator/config/crud_todo_config.freezed.dart b/lib/navigator/config/crud_todo_config.freezed.dart new file mode 100644 index 0000000..48557d3 --- /dev/null +++ b/lib/navigator/config/crud_todo_config.freezed.dart @@ -0,0 +1,710 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'crud_todo_config.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$CrudTodoConfigTearOff { + const _$CrudTodoConfigTearOff(); + + CrudTodoConfigCategoryList categoryList() { + return const CrudTodoConfigCategoryList(); + } + + CrudTodoConfigTodoList todoList(String categoryId) { + return CrudTodoConfigTodoList( + categoryId, + ); + } + + CrudTodoConfigAddTodo addTodo(String categoryId) { + return CrudTodoConfigAddTodo( + categoryId, + ); + } + + CrudTodoConfigUpdateTodo updateTodo(String categoryId, String todoId) { + return CrudTodoConfigUpdateTodo( + categoryId, + todoId, + ); + } + + CrudTodoConfigUnknown unknown() { + return const CrudTodoConfigUnknown(); + } +} + +/// @nodoc +const $CrudTodoConfig = _$CrudTodoConfigTearOff(); + +/// @nodoc +mixin _$CrudTodoConfig { + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CrudTodoConfigCopyWith<$Res> { + factory $CrudTodoConfigCopyWith( + CrudTodoConfig value, $Res Function(CrudTodoConfig) then) = + _$CrudTodoConfigCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigCopyWith<$Res> { + _$CrudTodoConfigCopyWithImpl(this._value, this._then); + + final CrudTodoConfig _value; + // ignore: unused_field + final $Res Function(CrudTodoConfig) _then; +} + +/// @nodoc +abstract class $CrudTodoConfigCategoryListCopyWith<$Res> { + factory $CrudTodoConfigCategoryListCopyWith(CrudTodoConfigCategoryList value, + $Res Function(CrudTodoConfigCategoryList) then) = + _$CrudTodoConfigCategoryListCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CrudTodoConfigCategoryListCopyWithImpl<$Res> + extends _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigCategoryListCopyWith<$Res> { + _$CrudTodoConfigCategoryListCopyWithImpl(CrudTodoConfigCategoryList _value, + $Res Function(CrudTodoConfigCategoryList) _then) + : super(_value, (v) => _then(v as CrudTodoConfigCategoryList)); + + @override + CrudTodoConfigCategoryList get _value => + super._value as CrudTodoConfigCategoryList; +} + +/// @nodoc + +class _$CrudTodoConfigCategoryList implements CrudTodoConfigCategoryList { + const _$CrudTodoConfigCategoryList(); + + @override + String toString() { + return 'CrudTodoConfig.categoryList()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is CrudTodoConfigCategoryList); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) { + return categoryList(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) { + if (categoryList != null) { + return categoryList(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) { + return categoryList(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) { + if (categoryList != null) { + return categoryList(this); + } + return orElse(); + } +} + +abstract class CrudTodoConfigCategoryList implements CrudTodoConfig { + const factory CrudTodoConfigCategoryList() = _$CrudTodoConfigCategoryList; +} + +/// @nodoc +abstract class $CrudTodoConfigTodoListCopyWith<$Res> { + factory $CrudTodoConfigTodoListCopyWith(CrudTodoConfigTodoList value, + $Res Function(CrudTodoConfigTodoList) then) = + _$CrudTodoConfigTodoListCopyWithImpl<$Res>; + $Res call({String categoryId}); +} + +/// @nodoc +class _$CrudTodoConfigTodoListCopyWithImpl<$Res> + extends _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigTodoListCopyWith<$Res> { + _$CrudTodoConfigTodoListCopyWithImpl(CrudTodoConfigTodoList _value, + $Res Function(CrudTodoConfigTodoList) _then) + : super(_value, (v) => _then(v as CrudTodoConfigTodoList)); + + @override + CrudTodoConfigTodoList get _value => super._value as CrudTodoConfigTodoList; + + @override + $Res call({ + Object? categoryId = freezed, + }) { + return _then(CrudTodoConfigTodoList( + categoryId == freezed + ? _value.categoryId + : categoryId // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$CrudTodoConfigTodoList implements CrudTodoConfigTodoList { + const _$CrudTodoConfigTodoList(this.categoryId); + + @override + final String categoryId; + + @override + String toString() { + return 'CrudTodoConfig.todoList(categoryId: $categoryId)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is CrudTodoConfigTodoList && + (identical(other.categoryId, categoryId) || + const DeepCollectionEquality() + .equals(other.categoryId, categoryId))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(categoryId); + + @JsonKey(ignore: true) + @override + $CrudTodoConfigTodoListCopyWith get copyWith => + _$CrudTodoConfigTodoListCopyWithImpl( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) { + return todoList(categoryId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) { + if (todoList != null) { + return todoList(categoryId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) { + return todoList(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) { + if (todoList != null) { + return todoList(this); + } + return orElse(); + } +} + +abstract class CrudTodoConfigTodoList implements CrudTodoConfig { + const factory CrudTodoConfigTodoList(String categoryId) = + _$CrudTodoConfigTodoList; + + String get categoryId => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CrudTodoConfigTodoListCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CrudTodoConfigAddTodoCopyWith<$Res> { + factory $CrudTodoConfigAddTodoCopyWith(CrudTodoConfigAddTodo value, + $Res Function(CrudTodoConfigAddTodo) then) = + _$CrudTodoConfigAddTodoCopyWithImpl<$Res>; + $Res call({String categoryId}); +} + +/// @nodoc +class _$CrudTodoConfigAddTodoCopyWithImpl<$Res> + extends _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigAddTodoCopyWith<$Res> { + _$CrudTodoConfigAddTodoCopyWithImpl( + CrudTodoConfigAddTodo _value, $Res Function(CrudTodoConfigAddTodo) _then) + : super(_value, (v) => _then(v as CrudTodoConfigAddTodo)); + + @override + CrudTodoConfigAddTodo get _value => super._value as CrudTodoConfigAddTodo; + + @override + $Res call({ + Object? categoryId = freezed, + }) { + return _then(CrudTodoConfigAddTodo( + categoryId == freezed + ? _value.categoryId + : categoryId // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$CrudTodoConfigAddTodo implements CrudTodoConfigAddTodo { + const _$CrudTodoConfigAddTodo(this.categoryId); + + @override + final String categoryId; + + @override + String toString() { + return 'CrudTodoConfig.addTodo(categoryId: $categoryId)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is CrudTodoConfigAddTodo && + (identical(other.categoryId, categoryId) || + const DeepCollectionEquality() + .equals(other.categoryId, categoryId))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(categoryId); + + @JsonKey(ignore: true) + @override + $CrudTodoConfigAddTodoCopyWith get copyWith => + _$CrudTodoConfigAddTodoCopyWithImpl( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) { + return addTodo(categoryId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) { + if (addTodo != null) { + return addTodo(categoryId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) { + return addTodo(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) { + if (addTodo != null) { + return addTodo(this); + } + return orElse(); + } +} + +abstract class CrudTodoConfigAddTodo implements CrudTodoConfig { + const factory CrudTodoConfigAddTodo(String categoryId) = + _$CrudTodoConfigAddTodo; + + String get categoryId => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CrudTodoConfigAddTodoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CrudTodoConfigUpdateTodoCopyWith<$Res> { + factory $CrudTodoConfigUpdateTodoCopyWith(CrudTodoConfigUpdateTodo value, + $Res Function(CrudTodoConfigUpdateTodo) then) = + _$CrudTodoConfigUpdateTodoCopyWithImpl<$Res>; + $Res call({String categoryId, String todoId}); +} + +/// @nodoc +class _$CrudTodoConfigUpdateTodoCopyWithImpl<$Res> + extends _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigUpdateTodoCopyWith<$Res> { + _$CrudTodoConfigUpdateTodoCopyWithImpl(CrudTodoConfigUpdateTodo _value, + $Res Function(CrudTodoConfigUpdateTodo) _then) + : super(_value, (v) => _then(v as CrudTodoConfigUpdateTodo)); + + @override + CrudTodoConfigUpdateTodo get _value => + super._value as CrudTodoConfigUpdateTodo; + + @override + $Res call({ + Object? categoryId = freezed, + Object? todoId = freezed, + }) { + return _then(CrudTodoConfigUpdateTodo( + categoryId == freezed + ? _value.categoryId + : categoryId // ignore: cast_nullable_to_non_nullable + as String, + todoId == freezed + ? _value.todoId + : todoId // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$CrudTodoConfigUpdateTodo implements CrudTodoConfigUpdateTodo { + const _$CrudTodoConfigUpdateTodo(this.categoryId, this.todoId); + + @override + final String categoryId; + @override + final String todoId; + + @override + String toString() { + return 'CrudTodoConfig.updateTodo(categoryId: $categoryId, todoId: $todoId)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is CrudTodoConfigUpdateTodo && + (identical(other.categoryId, categoryId) || + const DeepCollectionEquality() + .equals(other.categoryId, categoryId)) && + (identical(other.todoId, todoId) || + const DeepCollectionEquality().equals(other.todoId, todoId))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(categoryId) ^ + const DeepCollectionEquality().hash(todoId); + + @JsonKey(ignore: true) + @override + $CrudTodoConfigUpdateTodoCopyWith get copyWith => + _$CrudTodoConfigUpdateTodoCopyWithImpl( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) { + return updateTodo(categoryId, todoId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) { + if (updateTodo != null) { + return updateTodo(categoryId, todoId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) { + return updateTodo(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) { + if (updateTodo != null) { + return updateTodo(this); + } + return orElse(); + } +} + +abstract class CrudTodoConfigUpdateTodo implements CrudTodoConfig { + const factory CrudTodoConfigUpdateTodo(String categoryId, String todoId) = + _$CrudTodoConfigUpdateTodo; + + String get categoryId => throw _privateConstructorUsedError; + String get todoId => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CrudTodoConfigUpdateTodoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CrudTodoConfigUnknownCopyWith<$Res> { + factory $CrudTodoConfigUnknownCopyWith(CrudTodoConfigUnknown value, + $Res Function(CrudTodoConfigUnknown) then) = + _$CrudTodoConfigUnknownCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CrudTodoConfigUnknownCopyWithImpl<$Res> + extends _$CrudTodoConfigCopyWithImpl<$Res> + implements $CrudTodoConfigUnknownCopyWith<$Res> { + _$CrudTodoConfigUnknownCopyWithImpl( + CrudTodoConfigUnknown _value, $Res Function(CrudTodoConfigUnknown) _then) + : super(_value, (v) => _then(v as CrudTodoConfigUnknown)); + + @override + CrudTodoConfigUnknown get _value => super._value as CrudTodoConfigUnknown; +} + +/// @nodoc + +class _$CrudTodoConfigUnknown implements CrudTodoConfigUnknown { + const _$CrudTodoConfigUnknown(); + + @override + String toString() { + return 'CrudTodoConfig.unknown()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is CrudTodoConfigUnknown); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() categoryList, + required TResult Function(String categoryId) todoList, + required TResult Function(String categoryId) addTodo, + required TResult Function(String categoryId, String todoId) updateTodo, + required TResult Function() unknown, + }) { + return unknown(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? categoryList, + TResult Function(String categoryId)? todoList, + TResult Function(String categoryId)? addTodo, + TResult Function(String categoryId, String todoId)? updateTodo, + TResult Function()? unknown, + required TResult orElse(), + }) { + if (unknown != null) { + return unknown(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(CrudTodoConfigCategoryList value) categoryList, + required TResult Function(CrudTodoConfigTodoList value) todoList, + required TResult Function(CrudTodoConfigAddTodo value) addTodo, + required TResult Function(CrudTodoConfigUpdateTodo value) updateTodo, + required TResult Function(CrudTodoConfigUnknown value) unknown, + }) { + return unknown(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(CrudTodoConfigCategoryList value)? categoryList, + TResult Function(CrudTodoConfigTodoList value)? todoList, + TResult Function(CrudTodoConfigAddTodo value)? addTodo, + TResult Function(CrudTodoConfigUpdateTodo value)? updateTodo, + TResult Function(CrudTodoConfigUnknown value)? unknown, + required TResult orElse(), + }) { + if (unknown != null) { + return unknown(this); + } + return orElse(); + } +} + +abstract class CrudTodoConfigUnknown implements CrudTodoConfig { + const factory CrudTodoConfigUnknown() = _$CrudTodoConfigUnknown; +} diff --git a/lib/navigator/crud_todo_information_parser.dart b/lib/navigator/crud_todo_information_parser.dart index bbf995e..d76756f 100644 --- a/lib/navigator/crud_todo_information_parser.dart +++ b/lib/navigator/crud_todo_information_parser.dart @@ -16,12 +16,12 @@ class CrudTodoInformationParser extends RouteInformationParser { if (uri.pathSegments.isEmpty) { // Home '/' - return const CrudTodoConfig.categoryList(); + return const CrudTodoConfigCategoryList(); } else if (uri.pathSegments.length == 1) { // Home '/categories' final firstSegment = uri.pathSegments[0].toLowerCase(); if (firstSegment == CrudTodoPath.category) { - return const CrudTodoConfig.categoryList(); + return const CrudTodoConfigCategoryList(); } } else if (uri.pathSegments.length == 2) { // Category detail '/categories/{id}' @@ -30,7 +30,7 @@ class CrudTodoInformationParser extends RouteInformationParser { if (firstSegment == CrudTodoPath.category) { if (secondSegment.isNotEmpty) { - return CrudTodoConfig.todoList(categoryId: secondSegment); + return CrudTodoConfigTodoList(secondSegment); } } } else if (uri.pathSegments.length == 3) { @@ -42,7 +42,7 @@ class CrudTodoInformationParser extends RouteInformationParser { if (firstSegment == CrudTodoPath.category) { if (secondSegment.isNotEmpty) { if (thirdSegment == CrudTodoPath.todo) { - return CrudTodoConfig.addTodo(categoryId: secondSegment); + return CrudTodoConfigAddTodo(secondSegment); } } } @@ -57,10 +57,7 @@ class CrudTodoInformationParser extends RouteInformationParser { if (secondSegment.isNotEmpty) { if (thirdSegment == CrudTodoPath.todo) { if (lastSegment.isNotEmpty) { - return CrudTodoConfig.updateTodo( - categoryId: secondSegment, - todoId: lastSegment, - ); + return CrudTodoConfigUpdateTodo(secondSegment, lastSegment); } } } @@ -72,36 +69,27 @@ class CrudTodoInformationParser extends RouteInformationParser { @override RouteInformation? restoreRouteInformation(CrudTodoConfig configuration) { - if (configuration.isUnknown) { - return const RouteInformation(location: '/${CrudTodoPath.unknown}'); - } else if (configuration.isCategoryListPage) { - const categoryPath = CrudTodoPath.category; - - return const RouteInformation(location: '/$categoryPath'); - } else if (configuration.isTodoListPage) { - const categoryPath = CrudTodoPath.category; - final currentCategoryId = configuration.currentCategoryId; - - return RouteInformation(location: '/$categoryPath/$currentCategoryId'); - } else if (configuration.isAddTodoPage) { - const categoryPath = CrudTodoPath.category; - final currentCategoryId = configuration.currentCategoryId; - const todoPath = CrudTodoPath.todo; - - return RouteInformation( - location: '/$categoryPath/$currentCategoryId/$todoPath/', - ); - } else if (configuration.isUpdateTodoPage) { - const categoryPath = CrudTodoPath.category; - final currentCategoryId = configuration.currentCategoryId; - const todoPath = CrudTodoPath.todo; - final currentTodoId = configuration.currentTodoId; - - return RouteInformation( - location: '/$categoryPath/$currentCategoryId/$todoPath/$currentTodoId', - ); - } - - return null; + return configuration.when( + categoryList: () { + return const RouteInformation(location: '/${CrudTodoPath.category}'); + }, + todoList: (categoryId) { + const categoryPath = CrudTodoPath.category; + return RouteInformation(location: '/$categoryPath/$categoryId'); + }, + addTodo: (categoryId) { + const catPath = CrudTodoPath.category; + const todoPath = CrudTodoPath.todo; + return RouteInformation(location: '/$catPath/$categoryId/$todoPath/'); + }, + updateTodo: (id, todoId) { + const catPath = CrudTodoPath.category; + const todoPath = CrudTodoPath.todo; + return RouteInformation(location: '/$catPath/$id/$todoPath/$todoId'); + }, + unknown: () { + return const RouteInformation(location: '/${CrudTodoPath.unknown}'); + }, + ); } } diff --git a/lib/navigator/crud_todo_router_delegate.dart b/lib/navigator/crud_todo_router_delegate.dart index 1756dff..4129d91 100644 --- a/lib/navigator/crud_todo_router_delegate.dart +++ b/lib/navigator/crud_todo_router_delegate.dart @@ -36,7 +36,7 @@ class CrudTodoRouterDelegate extends RouterDelegate bool get isTodoSelected => _isTodoSelected; - void selectCurrentTodo(String? value, bool isSelected) { + void selectCurrentTodo(String? value, {required bool isSelected}) { _todoId = value; _isTodoSelected = isSelected; @@ -86,7 +86,10 @@ class CrudTodoRouterDelegate extends RouterDelegate if (categoryId != null) TodoPage( categoryId: categoryId!, - onGoToTodo: (catId, todoId) => selectCurrentTodo(todoId, true), + onGoToTodo: (catId, todoId) => selectCurrentTodo( + todoId, + isSelected: true, + ), ), if (categoryId != null && isTodoSelected) FormTodoPage(categoryId: categoryId!, todoId: todoId) @@ -96,7 +99,7 @@ class CrudTodoRouterDelegate extends RouterDelegate if (!route.didPop(result)) return false; if (!isTodoSelected) categoryId = null; - selectCurrentTodo(null, false); + selectCurrentTodo(null, isSelected: false); return true; }, @@ -106,42 +109,37 @@ class CrudTodoRouterDelegate extends RouterDelegate @override CrudTodoConfig? get currentConfiguration { if (isCategoryList) { - return const CrudTodoConfig.categoryList(); + return const CrudTodoConfigCategoryList(); } else if (isTodoList) { - return CrudTodoConfig.todoList(categoryId: categoryId); + return CrudTodoConfigTodoList(categoryId!); } else if (isTodoNew) { - return CrudTodoConfig.addTodo(categoryId: categoryId); + return CrudTodoConfigAddTodo(categoryId!); } else if (isTodoUpdate) { - return CrudTodoConfig.updateTodo(categoryId: categoryId, todoId: todoId); + return CrudTodoConfigUpdateTodo(categoryId!, todoId!); } else if (is404) { - return const CrudTodoConfig.unknown(); + return const CrudTodoConfigUnknown(); } return null; } @override - Future setNewRoutePath(CrudTodoConfig configuration) async { - if (configuration.isPageUnknown) { - _values(noFound: true); - } else if (configuration.isCategoryListPage) { - _values(); - } else if (configuration.isTodoListPage) { - _values(catId: configuration.currentCategoryId); - } else if (configuration.isAddTodoPage) { - _values(catId: configuration.currentCategoryId, selected: true); - } else if (configuration.isUpdateTodoPage) { - _values( - catId: configuration.currentCategoryId, - todoId: configuration.currentTodoId, - selected: true, + Future setNewRoutePath(CrudTodoConfig configuration) async => + configuration.when( + categoryList: _values, + todoList: (id) => _values(catId: id), + addTodo: (id) => _values(catId: id, selected: true), + updateTodo: (categoryId, todoId) => _values( + catId: categoryId, + todoId: todoId, + selected: true, + ), + unknown: () => _values(noFound: true), ); - } - } void _values({String? catId, String? todoId, bool? selected, bool? noFound}) { categoryId = catId; - selectCurrentTodo(todoId, selected ?? false); + selectCurrentTodo(todoId, isSelected: selected ?? false); is404 = noFound ?? false; } } diff --git a/lib/provider_dependency.dart b/lib/provider_dependency.dart index 1bc00d1..3e9240f 100644 --- a/lib/provider_dependency.dart +++ b/lib/provider_dependency.dart @@ -1,4 +1,6 @@ import 'package:cloud_firestore/cloud_firestore.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/repository/category_repository.dart'; import 'package:crud_todo_app/repository/todo_repository.dart'; import 'package:crud_todo_app/service/category_service.dart'; @@ -43,3 +45,15 @@ final todoViewModelPod = StateNotifierProvider( (ref) => TodoViewModel(ref.watch(todoRepositoryPod)), ); //endregion + +//region Navigator 2.0 + +final crudTodoRouterDelegateProvider = ChangeNotifierProvider( + (_) => CrudTodoRouterDelegate(), +); + +final crudTodoInformationParserProvider = Provider( + (ref) => CrudTodoInformationParser(), +); + +//endregion diff --git a/lib/viewmodel/todo/todo_provider.dart b/lib/viewmodel/todo/todo_provider.dart index f29be4b..1ce0cf9 100644 --- a/lib/viewmodel/todo/todo_provider.dart +++ b/lib/viewmodel/todo/todo_provider.dart @@ -13,7 +13,7 @@ final todoDetailPod = FutureProvider.autoDispose.family( final params = param.split(','); return params[0].isNotEmpty && params[1].isNotEmpty ? ref.watch(todoRepositoryPod).getTodoById(params[0], params[1]) - : Future.value(null); + : Future.value(); }, ); diff --git a/test/ui/category_list_view_test.dart b/test/ui/category_list_view_test.dart index d3aa127..8937ae1 100644 --- a/test/ui/category_list_view_test.dart +++ b/test/ui/category_list_view_test.dart @@ -53,7 +53,7 @@ void main() { child: MaterialApp( home: child, navigatorObservers: [mockNavigator], - // TODO: Review unit test for Navigator 2.0 + // TODO(FabianV): Review unit test for Navigator 2.0 // Navigator( // observers: [mockNavigator], // pages: >[ diff --git a/test/ui/todo_list_view_test.dart b/test/ui/todo_list_view_test.dart index d3aa127..8937ae1 100644 --- a/test/ui/todo_list_view_test.dart +++ b/test/ui/todo_list_view_test.dart @@ -53,7 +53,7 @@ void main() { child: MaterialApp( home: child, navigatorObservers: [mockNavigator], - // TODO: Review unit test for Navigator 2.0 + // TODO(FabianV): Review unit test for Navigator 2.0 // Navigator( // observers: [mockNavigator], // pages: >[ diff --git a/test/ui/unknown_view_test.dart b/test/ui/unknown_view_test.dart index e7ba177..2e440ee 100644 --- a/test/ui/unknown_view_test.dart +++ b/test/ui/unknown_view_test.dart @@ -13,12 +13,11 @@ void main() { }); Future _pumpMainScreen(WidgetTester tester, Widget child) async { - await tester.pumpWidget(ProviderScope( - child: MaterialApp( - home: child, - navigatorObservers: [mockNavigator], + await tester.pumpWidget( + ProviderScope( + child: MaterialApp(home: child, navigatorObservers: [mockNavigator]), ), - )); + ); } group('$UnknownView UI screen', () {