Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #177 from Leptopoda/feature/v1.1.0
Browse files Browse the repository at this point in the history
Feature/v1.1.0
  • Loading branch information
Teifun2 authored Mar 25, 2023
2 parents 5a3556d + 4df5466 commit fdf252f
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/src/blocs/recipe/recipe_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
) async* {
try {
yield RecipeUpdateInProgress();
final int recipeId =
final String recipeId =
await dataRepository.updateRecipe(recipeUpdated.recipe);
yield RecipeUpdateSuccess(recipeId);
} catch (_) {
Expand All @@ -51,7 +51,7 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
) async* {
try {
yield RecipeCreateInProgress();
final int recipeId =
final String recipeId =
await dataRepository.createRecipe(recipeCreated.recipe);
yield RecipeCreateSuccess(recipeId);
} catch (_) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/blocs/recipe/recipe_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ abstract class RecipeEvent extends Equatable {
}

class RecipeLoaded extends RecipeEvent {
final int recipeId;
final String recipeId;

const RecipeLoaded(this.recipeId);

@override
List<int> get props => [recipeId];
List<String> get props => [recipeId];
}

class RecipeUpdated extends RecipeEvent {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/blocs/recipe/recipe_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class RecipeUpdateFailure extends RecipeFailure {
}

class RecipeUpdateSuccess extends RecipeState {
final int recipeId;
final String recipeId;

const RecipeUpdateSuccess(this.recipeId);

@override
List<int> get props => [recipeId];
List<String> get props => [recipeId];
}

class RecipeUpdateInProgress extends RecipeState {}
Expand All @@ -58,7 +58,7 @@ class RecipeCreateFailure extends RecipeFailure {
}

class RecipeCreateSuccess extends RecipeState {
final int recipeId;
final String recipeId;

const RecipeCreateSuccess(this.recipeId);

Expand All @@ -69,12 +69,12 @@ class RecipeCreateSuccess extends RecipeState {
class RecipeCreateInProgress extends RecipeState {}

class RecipeImportSuccess extends RecipeState {
final int recipeId;
final String recipeId;

const RecipeImportSuccess(this.recipeId);

@override
List<int> get props => [recipeId];
List<String> get props => [recipeId];
}

class RecipeImportFailure extends RecipeFailure {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/models/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Category extends Equatable {
final String name;
@CopyWithField(immutable: true)
final int recipeCount;
final int firstRecipeId;
final String? firstRecipeId;

const Category(this.name, this.recipeCount) : firstRecipeId = 0;
const Category(this.name, this.recipeCount) : firstRecipeId = null;

const Category._({
required this.name,
Expand All @@ -26,7 +26,7 @@ class Category extends Equatable {
recipeCount = json["recipe_count"] is int
? json["recipe_count"] as int
: int.parse(json["recipe_count"] as String),
firstRecipeId = 0;
firstRecipeId = null;

@override
List<String> get props => [name];
Expand Down
16 changes: 7 additions & 9 deletions lib/src/models/category.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions lib/src/models/recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:nextcloud_cookbook_flutter/src/util/iso_time_format.dart';
import 'package:nextcloud_cookbook_flutter/src/util/nutrition_utilty.dart';

class Recipe extends Equatable {
final int id;
final String id;
final String name;
final String imageUrl;
final String recipeCategory;
Expand All @@ -26,11 +26,12 @@ class Recipe extends Equatable {
factory Recipe(String jsonString) {
final data = json.decode(jsonString) as Map<String, dynamic>;

final int id = data["id"] as int? ?? 0;
final String name = data["name"] as String? ?? '';
final String imageUrl = data["imageUrl"] as String? ?? '';
final String recipeCategory = data["recipeCategory"] as String? ?? '';
final String description = data["description"] as String? ?? '';
final String id =
data["id"] is int ? data["id"]!.toString() : data["id"] as String;
final String name = data["name"] as String;
final String imageUrl = data["imageUrl"] as String;
final String recipeCategory = data["recipeCategory"] as String;
final String description = data["description"] as String;

Map<String, String> recipeNutrition = {};

Expand Down Expand Up @@ -152,7 +153,7 @@ class Recipe extends Equatable {

factory Recipe.empty() {
return Recipe._(
0,
'0',
'',
'',
'',
Expand Down Expand Up @@ -229,7 +230,7 @@ class Recipe extends Equatable {
}

@override
List<int> get props => [id];
List<String> get props => [id];

String _durationToIso(Duration? duration) {
if (duration != null && duration.inMinutes != 0) {
Expand All @@ -241,7 +242,7 @@ class Recipe extends Equatable {
}

class MutableRecipe {
int id = 0;
String id = '0';
String name = '';
String imageUrl = '';
String recipeCategory = '';
Expand Down
10 changes: 5 additions & 5 deletions lib/src/models/recipe_short.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'dart:convert';
import 'package:equatable/equatable.dart';

class RecipeShort extends Equatable {
final int _recipeId;
final String _recipeId;
final String _name;
final String _imageUrl;

int get recipeId => _recipeId;
String get recipeId => _recipeId;
String get name => _name;
String get imageUrl => _imageUrl;

RecipeShort.fromJson(Map<String, dynamic> json)
: _recipeId = json["recipe_id"] is int
? json["recipe_id"] as int
: int.parse(json["recipe_id"] as String),
? json["recipe_id"]!.toString()
: json["recipe_id"] as String,
_name = json["name"] as String,
_imageUrl = json["imageUrl"] as String;

Expand All @@ -29,5 +29,5 @@ class RecipeShort extends Equatable {
}

@override
List<int> get props => [_recipeId];
List<String> get props => [_recipeId];
}
12 changes: 7 additions & 5 deletions lib/src/models/timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:nextcloud_cookbook_flutter/src/services/notification_provider.da
import 'package:timezone/timezone.dart' as tz;

class TimerList {
static const TimerList _instance = TimerList._();
static final TimerList _instance = TimerList._();
final List<Timer> timers;

factory TimerList() => _instance;

const TimerList._() : timers = const <Timer>[];
TimerList._() : timers = <Timer>[];

List<Timer> get(int recipeId) {
List<Timer> get(String recipeId) {
final List<Timer> l = <Timer>[];
for (final value in timers) {
if (value.recipeId == recipeId) l.add(value);
Expand All @@ -29,7 +29,7 @@ class Timer {
final Duration duration;
int id = 0;
final tz.TZDateTime done;
final int recipeId;
final String recipeId;

Timer(
this.recipeId,
Expand All @@ -50,7 +50,9 @@ class Timer {

factory Timer.fromJson(Map<String, dynamic> json, int id) {
final Timer timer = Timer._restore(
json['recipeId'] as int,
json['recipeId'] is String
? json['recipeId'] as String
: json['recipeId'].toString(),
json['title'] as String,
json['body'] as String,
Duration(minutes: json['duration'] as int),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/recipe/recipe_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:url_launcher/url_launcher_string.dart';
import 'package:wakelock/wakelock.dart';

class RecipeScreen extends StatefulWidget {
final int recipeId;
final String recipeId;

const RecipeScreen({
super.key,
Expand Down
15 changes: 9 additions & 6 deletions lib/src/services/data_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ class DataRepository {
}
}

Future<Recipe> fetchRecipe(int id) {
return recipeProvider.fetchRecipe(id);
Future<Recipe> fetchRecipe(String id) {
return recipeProvider.fetchRecipe(int.parse(id));
}

Future<int> updateRecipe(Recipe recipe) {
return recipeProvider.updateRecipe(recipe);
Future<String> updateRecipe(Recipe recipe) async {
final response = await recipeProvider.updateRecipe(recipe);
return response.toString();
}

Future<int> createRecipe(Recipe recipe) {
return recipeProvider.createRecipe(recipe);
Future<String> createRecipe(Recipe recipe) async {
final response = await recipeProvider.createRecipe(recipe);

return response.toString();
}

Future<Recipe> importRecipe(String url) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/version_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class VersionProvider {

class ApiVersion {
static const int confirmedMajorAPIVersion = 1;
static const int confirmedMinorAPIVersion = 0;
static const int confirmedMinorAPIVersion = 1;

final int majorApiVersion;
final int minorApiVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AuthenticationCachedNetworkRecipeImage extends StatelessWidget {
final double? height;
final BoxFit? boxFit;

final int recipeId;
final String recipeId;
final bool full;

const AuthenticationCachedNetworkRecipeImage({
Expand Down
4 changes: 2 additions & 2 deletions lib/src/widget/category_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class CategoryCard extends StatelessWidget {
colors: <Color>[Colors.black, Colors.transparent],
).createShader(bounds);
},
child: category.firstRecipeId != 0
child: category.firstRecipeId != null
? ClipRRect(
borderRadius: BorderRadius.circular(5),
child: AuthenticationCachedNetworkRecipeImage(
recipeId: category.firstRecipeId,
recipeId: category.firstRecipeId!,
full: false,
boxFit: BoxFit.cover,
),
Expand Down

0 comments on commit fdf252f

Please sign in to comment.