Skip to content

Commit

Permalink
use very good analysis lints rules
Browse files Browse the repository at this point in the history
  • Loading branch information
reke592 committed Jan 14, 2024
1 parent 76cd364 commit 381b196
Show file tree
Hide file tree
Showing 52 changed files with 342 additions and 322 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Ale 🍻

[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)

Dev MUST learn to cook!

### Practice project for Flutter + BLoC using Clean Architecture
Expand Down
27 changes: 2 additions & 25 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

include: package:very_good_analysis/analysis_options.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
public_member_api_docs: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
16 changes: 9 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:ale/src/features/recipe/domain/repositories/food_recipe_repository.dart';
import 'package:ale/src/core/injection_container.dart';
import 'package:ale/src/features/recipe/domain/repositories/food_recipe_repository.dart';
import 'package:ale/src/router.dart';
import 'package:ale/src/ui/behaviors/app_scroll_behavior.dart';
import 'package:ale/src/ui/observers/app_bloc_observer.dart';
import 'package:ale/src/router.dart';
import 'package:ale/src/ui/themes/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -12,17 +12,19 @@ void main() async {
Bloc.observer = AppBlocObserver();
WidgetsFlutterBinding.ensureInitialized();
initStandardUsecases();
runApp(MyApp(
router: AppRouter(initialLocation: '/recipe'),
));
runApp(
MyApp(
router: AppRouter(initialLocation: '/recipe'),
),
);
}

class MyApp extends StatelessWidget {
final AppRouter router;
const MyApp({
super.key,
required this.router,
super.key,
});
final AppRouter router;

@override
Widget build(BuildContext context) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/commons/message_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ final class MessageDialog {
MessageDialog._();

static void showError(BuildContext context, Object error) {
showDialog(
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (dialogContext) {
Expand All @@ -19,7 +19,7 @@ final class MessageDialog {
},
icon: const Icon(Icons.close),
),
)
),
],
);
},
Expand Down Expand Up @@ -48,6 +48,6 @@ final class MessageDialog {
],
);
},
).then((value) => value == true);
).then((value) => value ?? false == true);
}
}
40 changes: 23 additions & 17 deletions lib/src/core/injection_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,33 @@ final inject = GetIt.I;
/// initialize standard use cases
void initStandardUsecases() {
inject
..registerFactory(() => RecipeListBloc(
repo: inject(),
getAllRecipes: inject(),
saveRecipe: inject(),
deleteRecepies: inject(),
))
..registerFactory(() => RecipeViewBloc(
repo: inject(),
saveRecipe: inject(),
))
..registerFactory(() => EditCookingStepBloc(
repo: inject(),
saveCookingStep: inject(),
deleteCookingStep: inject(),
))
..registerFactory(
() => RecipeListBloc(
repo: inject(),
getAllRecipes: inject(),
saveRecipe: inject(),
deleteRecepies: inject(),
),
)
..registerFactory(
() => RecipeViewBloc(
repo: inject(),
saveRecipe: inject(),
),
)
..registerFactory(
() => EditCookingStepBloc(
saveCookingStep: inject(),
deleteCookingStep: inject(),
),
)
..registerLazySingleton(() => DeleteCookingStep(inject()))
..registerLazySingleton(() => DeleteRecepies(inject()))
..registerLazySingleton(() => GetAllRecipes(inject()))
..registerLazySingleton(() => SaveCookingStep(inject()))
..registerLazySingleton(() => SaveRecipe(inject()))
..registerLazySingleton<FoodRecipeRepository>(
() => FoodRecipeRepositoryImplementation(inject()))
..registerLazySingleton<RecipeDataSource>(() => RecipeMemoryDataSource());
() => FoodRecipeRepositoryImplementation(inject()),
)
..registerLazySingleton<RecipeDataSource>(RecipeMemoryDataSource.new);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ class RecipeMemoryDataSource extends RecipeDataSource {
id: 1,
name: 'Spicy Garlic Butter Seafood',
description:
'This special sauce is so delicious and for the better result use fresh seafoods. '
'Enjoy it with white rice/fried rice or pineapple rice.',
'This special sauce is so delicious and for the better result use '
'fresh seafoods. Enjoy it with white rice/fried rice or pineapple rice.',
serving: 2,
steps: [
CookingStepModel(
number: 1,
active: true,
duration: Duration(),
ingredients: [
IngredientModel(name: 'Black Peppercorns', amount: 2, unit: 'tsp'),
IngredientModel(name: 'Water', amount: 2, unit: 'l'),
Expand All @@ -26,7 +24,6 @@ class RecipeMemoryDataSource extends RecipeDataSource {
),
CookingStepModel(
number: 2,
active: true,
duration: Duration(minutes: 2),
ingredients: [
IngredientModel(name: 'Shrimp', amount: 200, unit: 'g'),
Expand All @@ -35,39 +32,44 @@ class RecipeMemoryDataSource extends RecipeDataSource {
IngredientModel(name: 'Sweet Corn', amount: 2, unit: 'pc'),
],
instructions:
'Boil all ingredients. For shrimp, boil until it\'s pink. It takes about 2 minutes. '
'And continue boil the rest of ingredients until they are cooked/soft. '
'Strained, set a side.',
"Boil all ingredients. For shrimp, boil until it's pink. "
'It takes about 2 minutes. And continue boil the rest of '
'ingredients until they are cooked/soft. Strained, set a side.',
),
CookingStepModel(
number: 3,
active: true,
duration: Duration(minutes: 5),
ingredients: [
IngredientModel(name: 'Butter', amount: 250, unit: 'g'),
IngredientModel(
name: 'Korean chili paste', amount: 2, unit: 'tbsp'),
name: 'Korean chili paste',
amount: 2,
unit: 'tbsp',
),
IngredientModel(
name: 'yellow Thai curry paste', amount: 1, unit: 'package'),
name: 'yellow Thai curry paste',
amount: 1,
unit: 'package',
),
IngredientModel(name: 'Chicken stock', amount: 200, unit: 'ml'),
IngredientModel(name: 'Garlic', amount: 5, unit: 'cloves'),
IngredientModel(name: 'Olive Oil', amount: 2, unit: 'tbsp'),
IngredientModel(name: 'Salt', amount: 2, unit: 'tsp'),
IngredientModel(name: 'Brown Sugar', amount: 3, unit: 'tbsp'),
],
instructions:
'In a frying pan, first add olive oil and fry the onion and garlic until it’s fragrance. '
'Next add butter until completely melted.Add Korean Chili paste, yellow Thai curry paste, '
'brown sugar, salt and the remaining black peppercorn. Last add chicken stock. '
'Let it simmer for about 5 minutes. Turn off the gas.',
'In a frying pan, first add olive oil and fry the onion and '
'garlic until it’s fragrance. Next add butter until completely '
'melted.Add Korean Chili paste, yellow Thai curry paste, '
'brown sugar, salt and the remaining black peppercorn. '
'Last add chicken stock. Let it simmer for about 5 minutes. '
'Turn off the gas.',
),
CookingStepModel(
number: 4,
active: true,
duration: Duration(),
ingredients: [],
instructions:
'Add the shrimp, calamari, mussels and corn to the pan. Mixed with the sauce until it’s combined. '
'Add the shrimp, calamari, mussels and corn to the pan. '
'Mixed with the sauce until it’s combined. '
'And your spicy garlic butter seafood is ready!',
),
],
Expand All @@ -82,7 +84,7 @@ class RecipeMemoryDataSource extends RecipeDataSource {
@override
Future<void> delete(List<int> ids) async {
if (ids.isNotEmpty) {
for (var id in ids) {
for (final id in ids) {
_data.removeWhere((element) => element.id == id);
}
}
Expand Down Expand Up @@ -126,7 +128,7 @@ class RecipeMemoryDataSource extends RecipeDataSource {
}) async {
final index = _data.indexWhere((element) => element.id == recipeId);
if (index == -1) throw Exception('recipe not found');
FoodRecipeModel record = _data[index];
var record = _data[index];
CookingStepModel updatedStep;
final stepIndex =
record.steps.indexWhere((element) => element.number == number);
Expand Down
14 changes: 7 additions & 7 deletions lib/src/features/recipe/data/models/cooking_step_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Duration _durationFromString(String value) {
class CookingStepModel extends CookingStep {
const CookingStepModel({
required super.number,
super.duration = const Duration(),
super.duration = Duration.zero,
super.ingredients = const [],
super.instructions = '',
super.active = true,
Expand All @@ -21,23 +21,23 @@ class CookingStepModel extends CookingStep {
const CookingStepModel.empty()
: this(
number: 0,
duration: const Duration(),
duration: Duration.zero,
ingredients: const [],
instructions: 'instructions',
active: true,
);

factory CookingStepModel.fromJson(String source) =>
CookingStepModel.fromMap(jsonDecode(source));
CookingStepModel.fromMap(jsonDecode(source) as Map<String, dynamic>);

factory CookingStepModel.fromMap(DataMap json) => CookingStepModel(
number: json['number'],
duration: _durationFromString(json['duration']),
number: json['number'] as int,
duration: _durationFromString(json['duration'] as String),
active: json['active'] == 1,
ingredients: List<DataMap>.from(json['ingredients'])
ingredients: List<DataMap>.from(json['ingredients'] as List<DataMap>)
.map(IngredientModel.fromMap)
.toList(),
instructions: json['instructions'],
instructions: json['instructions'] as String,
);

DataMap toMap() => {
Expand Down
14 changes: 7 additions & 7 deletions lib/src/features/recipe/data/models/food_recipe_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'package:ale/src/features/recipe/domain/entities/food_recipe.dart';
class FoodRecipeModel extends FoodRecipe {
/// {@macro food_recipe}
const FoodRecipeModel({
super.id,
required super.name,
required super.serving,
super.id,
super.steps = const [],
super.description = '',
});
Expand All @@ -27,14 +27,14 @@ class FoodRecipeModel extends FoodRecipe {
);

factory FoodRecipeModel.fromJson(String source) =>
FoodRecipeModel.fromMap(jsonDecode(source));
FoodRecipeModel.fromMap(jsonDecode(source) as Map<String, dynamic>);

factory FoodRecipeModel.fromMap(DataMap json) => FoodRecipeModel(
id: json['id'],
name: json['name'],
serving: json['serving'],
description: json['description'],
steps: List<DataMap>.from(json['steps'])
id: json['id'] as int,
name: json['name'] as String,
serving: json['serving'] as int,
description: json['description'] as String,
steps: List<DataMap>.from(json['steps'] as List<DataMap>)
.map(CookingStepModel.fromMap)
.toList(),
);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/features/recipe/data/models/ingredient_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class IngredientModel extends Ingredient {
);

factory IngredientModel.fromJson(String source) =>
IngredientModel.fromMap(jsonDecode(source));
IngredientModel.fromMap(jsonDecode(source) as DataMap);

factory IngredientModel.fromMap(DataMap json) => IngredientModel(
name: json['name'],
amount: json['amount'],
unit: json['unit'],
name: json['name'] as String,
amount: json['amount'] as double,
unit: json['unit'] as String,
);

DataMap toMap() => {
Expand Down
15 changes: 7 additions & 8 deletions lib/src/features/recipe/domain/entities/cooking_step.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
part of 'food_recipe.dart';

class CookingStep extends Equatable {
final int number;

/// cooking duration
final Duration duration;
final List<Ingredient> ingredients;
final String instructions;
final bool active;

const CookingStep({
required this.number,
required this.duration,
required this.ingredients,
required this.instructions,
required this.active,
});
final int number;

/// cooking duration
final Duration duration;
final List<Ingredient> ingredients;
final String instructions;
final bool active;

@override
List<Object?> get props => [
Expand Down
11 changes: 5 additions & 6 deletions lib/src/features/recipe/domain/entities/food_recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ part 'ingredient.dart';
/// Food Recipe domain aggregate root entity.
/// {@endtemplate}
class FoodRecipe extends Equatable {
final int? id;
final String name;
final String description;
final int serving;
final List<CookingStep> steps;

/// {@macro food_recipe}
const FoodRecipe({
required this.id,
Expand All @@ -21,6 +15,11 @@ class FoodRecipe extends Equatable {
required this.steps,
required this.description,
});
final int? id;
final String name;
final String description;
final int serving;
final List<CookingStep> steps;

/// list of all ingredients from cooking steps
List<Ingredient> get allIngredients => steps.fold(
Expand Down
Loading

0 comments on commit 381b196

Please sign in to comment.