-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nikolas Rimikis <[email protected]>
- Loading branch information
Showing
42 changed files
with
1,240 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 38 additions & 1 deletion
39
packages/neon_framework/packages/cookbook_app/lib/l10n/arb/cookbook_en.arb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
{ | ||
"@@locale": "en" | ||
"@@locale": "en", | ||
"recipeCreateButton": "Create Recipe", | ||
"@recipeCreateButton": { | ||
"type": "text", | ||
"description": "Button to open the create recipe screen" | ||
}, | ||
"recipeListTitle": "Category: {name}", | ||
"@recipeListTitle": { | ||
"type": "text", | ||
"description": "Title of the category view.", | ||
"placeholders": { | ||
"name": { | ||
"description": "The name of the category.", | ||
"type": "String", | ||
"example": "Vegan" | ||
} | ||
} | ||
}, | ||
"noRecipes": "No recipes available.", | ||
"errorLoadFailed": "Failed to load Recipe!", | ||
"@errorLoadFailed": { | ||
"type": "text", | ||
"description": "Error message when fetching the recipes failed." | ||
}, | ||
"categoryAll": "All Recipes", | ||
"categoryUncategorized": "Uncategorized", | ||
"categoryItems": "{count, plural, =0{no items} =1 {1 item} other {{count} items}}", | ||
"@categoryItems": { | ||
"type": "text", | ||
"description": "Number of recipes in a category.", | ||
"placeholders": { | ||
"count": { | ||
"description": "The number of recipes.", | ||
"type": "int", | ||
"example": "4" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/neon_framework/packages/cookbook_app/lib/src/categories/bloc/categories_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:cookbook_recipe_repository/recipe_repository.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
part 'categories_event.dart'; | ||
part 'categories_state.dart'; | ||
|
||
/// The bloc controlling the categories overview. | ||
final class CategoriesBloc extends Bloc<_CategoriesEvent, CategoriesState> { | ||
/// Creates a new categories bloc. | ||
CategoriesBloc({ | ||
required RecipeRepository recipeRepository, | ||
}) : _recipeRepository = recipeRepository, | ||
super(CategoriesState()) { | ||
on<RefreshCategories>(_onRefreshCategories); | ||
|
||
add(const RefreshCategories()); | ||
} | ||
|
||
final RecipeRepository _recipeRepository; | ||
|
||
Future<void> _onRefreshCategories( | ||
RefreshCategories event, | ||
Emitter<CategoriesState> emit, | ||
) async { | ||
try { | ||
emit(state.copyWith(status: CategoriesStatus.loading)); | ||
|
||
final categories = await _recipeRepository.readCategories(); | ||
|
||
emit( | ||
state.copyWith( | ||
categories: categories, | ||
status: CategoriesStatus.success, | ||
), | ||
); | ||
} on ReadCategoriesFailure { | ||
emit(state.copyWith(status: CategoriesStatus.failure)); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/neon_framework/packages/cookbook_app/lib/src/categories/bloc/categories_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
part of 'categories_bloc.dart'; | ||
|
||
/// Events for the [CategoriesBloc]. | ||
sealed class _CategoriesEvent extends Equatable { | ||
const _CategoriesEvent(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
/// {@template RefreshCategories} | ||
/// Event that triggers a reload of the categories. | ||
/// {@endtemplate} | ||
final class RefreshCategories extends _CategoriesEvent { | ||
/// {@macro RefreshCategories} | ||
const RefreshCategories(); | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/neon_framework/packages/cookbook_app/lib/src/categories/bloc/categories_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
part of 'categories_bloc.dart'; | ||
|
||
/// The status of the [CategoriesState]. | ||
enum CategoriesStatus { | ||
/// When no event has been handled. | ||
initial, | ||
|
||
/// When the categories are loading. | ||
loading, | ||
|
||
/// When the categories have been fetched successfully. | ||
success, | ||
|
||
/// When a failure occurred while loading the categories. | ||
failure, | ||
} | ||
|
||
/// State of the [CategoriesBloc]. | ||
final class CategoriesState extends Equatable { | ||
/// Creates a new state for managing the categories. | ||
CategoriesState({ | ||
BuiltList<Category>? categories, | ||
this.status = CategoriesStatus.initial, | ||
}) : categories = categories ?? BuiltList(); | ||
|
||
/// The list of categories. | ||
/// | ||
/// Defaults to an empty list. | ||
final BuiltList<Category> categories; | ||
|
||
/// The status of the state. | ||
final CategoriesStatus status; | ||
|
||
/// Creates a copies with mutated fields. | ||
CategoriesState copyWith({ | ||
BuiltList<Category>? categories, | ||
String? error, | ||
CategoriesStatus? status, | ||
}) { | ||
return CategoriesState( | ||
categories: categories ?? this.categories, | ||
status: status ?? this.status, | ||
); | ||
} | ||
|
||
@override | ||
List<Object> get props => [ | ||
categories, | ||
status, | ||
]; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/neon_framework/packages/cookbook_app/lib/src/categories/categories.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'bloc/categories_bloc.dart'; | ||
export 'utils/utils.dart'; | ||
export 'view/view.dart'; | ||
export 'widgets/widgets.dart'; |
44 changes: 44 additions & 0 deletions
44
...neon_framework/packages/cookbook_app/lib/src/categories/utils/category_grid_delegate.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:math' as math; | ||
|
||
import 'package:flutter/rendering.dart'; | ||
|
||
/// Controls the layout of the category cards in a grid. | ||
class CategoryGridDelegate extends SliverGridDelegate { | ||
/// Creates a delegate for the category card layout. | ||
const CategoryGridDelegate({ | ||
this.extent = 0.0, | ||
}); | ||
|
||
/// The height extend the card will take. | ||
final double extent; | ||
|
||
static const double _maxCrossAxisExtent = 250; | ||
static const double _mainAxisSpacing = 8; | ||
static const double _crossAxisSpacing = 8; | ||
|
||
@override | ||
SliverGridLayout getLayout(SliverConstraints constraints) { | ||
var crossAxisCount = (constraints.crossAxisExtent / (_maxCrossAxisExtent + _crossAxisSpacing)).ceil(); | ||
// Ensure a minimum count of 1, can be zero and result in an infinite extent | ||
// below when the window size is 0. | ||
crossAxisCount = math.max(1, crossAxisCount); | ||
final double usableCrossAxisExtent = math.max( | ||
0, | ||
constraints.crossAxisExtent - _crossAxisSpacing * (crossAxisCount - 1), | ||
); | ||
final childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount; | ||
final childMainAxisExtent = childCrossAxisExtent + extent; | ||
|
||
return SliverGridRegularTileLayout( | ||
crossAxisCount: crossAxisCount, | ||
mainAxisStride: childMainAxisExtent + _mainAxisSpacing, | ||
crossAxisStride: childCrossAxisExtent + _crossAxisSpacing, | ||
childMainAxisExtent: childMainAxisExtent, | ||
childCrossAxisExtent: childCrossAxisExtent, | ||
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), | ||
); | ||
} | ||
|
||
@override | ||
bool shouldRelayout(CategoryGridDelegate oldDelegate) => oldDelegate.extent != extent; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/neon_framework/packages/cookbook_app/lib/src/categories/utils/utils.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'category_grid_delegate.dart'; |
Oops, something went wrong.