aboutsummaryrefslogtreecommitdiff
path: root/lib/views/recipe_view.dart
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2022-08-24 15:38:58 +0200
committerdavidpkj <davidpenkow1@gmail.com>2022-08-24 15:38:58 +0200
commit33bb197557b6222d7db46e02c74fe8442833e295 (patch)
tree017036dc57cce28fac92aedbcad65249d4f4d1c1 /lib/views/recipe_view.dart
parente18cf14cc7d586a90283cf50678b6d53474ef3b8 (diff)
Minor bug fixes and updates
Diffstat (limited to 'lib/views/recipe_view.dart')
-rw-r--r--lib/views/recipe_view.dart72
1 files changed, 22 insertions, 50 deletions
diff --git a/lib/views/recipe_view.dart b/lib/views/recipe_view.dart
index a0304c3..92a50b7 100644
--- a/lib/views/recipe_view.dart
+++ b/lib/views/recipe_view.dart
@@ -3,13 +3,13 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:kulinar_app/constants.dart';
-import 'package:kulinar_app/models/data/shoplist_data_class.dart';
import 'package:kulinar_app/views/image_view.dart';
import 'package:kulinar_app/models/recipe_class.dart';
import 'package:kulinar_app/widgets/toastbar_widget.dart';
import 'package:kulinar_app/models/data/recipe_data_class.dart';
import 'package:kulinar_app/widgets/page_route_transitions.dart';
import 'package:kulinar_app/widgets/utility_icon_row_widget.dart';
+import 'package:kulinar_app/models/data/shoplist_data_class.dart';
import 'package:kulinar_app/models/data/settings_data_class.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
@@ -21,10 +21,9 @@ import 'package:http/http.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class RecipeView extends StatefulWidget {
- const RecipeView({Key? key, this.remote = false, required this.readonly, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key);
+ const RecipeView({Key? key, this.remote = false, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key);
final bool remote;
- final bool readonly;
final Recipe? recipe;
final Function? redrawCallback;
final Function? showToastCallback;
@@ -41,7 +40,7 @@ class _RecipeViewState extends State<RecipeView> {
final FocusNode _detailsTitleFocus = FocusNode();
final FocusNode _detailsTextFocus = FocusNode();
Recipe _unsavedRecipe = Recipe();
- bool _readonlyOverride = false;
+ bool _isEditModeEnabled = false;
Recipe? _removedRecipe;
@override
@@ -52,6 +51,7 @@ class _RecipeViewState extends State<RecipeView> {
if (_unsavedRecipe.isDefault()) {
_controller1.clear();
_controller2.clear();
+ _isEditModeEnabled = true;
} else {
_controller1.text = _unsavedRecipe.title ?? "";
_controller2.text = _unsavedRecipe.description ?? "";
@@ -97,16 +97,16 @@ class _RecipeViewState extends State<RecipeView> {
_unsavedRecipe.title = _controller1.text;
_unsavedRecipe.description = _controller2.text;
- if (!widget.readonly) {
- RecipeData.recipeList.add(_unsavedRecipe);
+ if (_isEditModeEnabled) {
+ if (!RecipeData.recipeList.contains(_unsavedRecipe)) RecipeData.recipeList.add(_unsavedRecipe);
RecipeData.save();
}
+ _isEditModeEnabled = false;
+
if (widget.recipe == null) {
Navigator.pop(context);
} else {
- _readonlyOverride = false;
-
setState(() {});
}
}
@@ -131,13 +131,6 @@ class _RecipeViewState extends State<RecipeView> {
setState(() {});
}
- bool _isEditingAllowed() {
- if (_readonlyOverride) return true;
- if (!widget.readonly) return true;
-
- return false;
- }
-
// TODO: FIXME: This might introduce bugs later (sanetize); maybe use FileHandler?
void downloadRecipe(BuildContext context, Recipe recipe) async {
RecipeData.recipeList.add(recipe);
@@ -186,13 +179,12 @@ class _RecipeViewState extends State<RecipeView> {
// _buildAppBarPhotoActions(recipe),
return UtilityIconRow(
remote: widget.remote,
- readonly: !_isEditingAllowed(),
+ isEditModeEnabled: _isEditModeEnabled,
unsavedRecipe: _unsavedRecipe,
pickImageCallback: _pickImage,
removeImageCallback: _removeImage,
removeRecipeCallback: _removeRecipe,
downloadRecipeCallback: downloadRecipe,
- isEditingAllowedCallback: _isEditingAllowed,
cacheUnsavedRecipeCallback: _cacheUnsavedRecipe,
);
}
@@ -205,7 +197,7 @@ class _RecipeViewState extends State<RecipeView> {
controller: _controller1,
style: cRecipeTitleStyle,
cursorColor: cPrimaryColor,
- enabled: _isEditingAllowed(),
+ enabled: _isEditModeEnabled,
focusNode: _detailsTitleFocus,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
@@ -257,7 +249,7 @@ class _RecipeViewState extends State<RecipeView> {
Widget _buildDescriptionInput() {
return Padding(
padding: const EdgeInsets.all(18.0),
- child: _isEditingAllowed() ? _buildInputDescriptuion() : _buildMarkdownDescription(),
+ child: _isEditModeEnabled ? _buildInputDescriptuion() : _buildMarkdownDescription(),
);
}
@@ -287,30 +279,7 @@ class _RecipeViewState extends State<RecipeView> {
selectable: true,
onTapLink: (text, href, title) => null,
imageBuilder: (uri, title, alt) => Container(),
- styleSheet: MarkdownStyleSheet(
- tableBody: cRecipeDescriptionStyle,
- a: cRecipeDescriptionStyle,
- p: cRecipeDescriptionStyle,
- h1: cRecipeSubtitleStyle,
- h2: cRecipeSubtitleStyle,
- h3: cRecipeSubtitleStyle,
- h4: cRecipeSubtitleStyle,
- h5: cRecipeSubtitleStyle,
- h6: cRecipeSubtitleStyle,
-/* TODO: remove code and quote block
- blockquoteDecoration: BoxDecoration(color: Color.fromARGB(255, 255, 13, 13)),
- code: cDetailsTextStyle,
-*/
- listIndent: 15.0,
- listBullet: cRecipeDescriptionStyle,
- listBulletPadding: EdgeInsets.only(right: 10.0),
- horizontalRuleDecoration: BoxDecoration(
- border: Border.all(
- color: Colors.grey,
- width: 0.5,
- ),
- ),
- ),
+ // styleSheet: CustomMarkdownStyle(),
);
}
@@ -321,6 +290,12 @@ class _RecipeViewState extends State<RecipeView> {
void _addToShoppingList(BuildContext _) {
final _ingredients = _unsavedRecipe.description!.split("\n")..retainWhere((element) => element.startsWith("- "));
+ if (_ingredients.isEmpty) {
+ // TODO: translation
+ widget.showToastCallback!("No ingredients found", "");
+ return;
+ }
+
for (String _ingredient in _ingredients) {
String _item = _ingredient.substring(2).trim();
@@ -333,10 +308,7 @@ class _RecipeViewState extends State<RecipeView> {
if (widget.showToastCallback != null) {
// TODO: translation
- widget.showToastCallback!("Added to Shoplist", "Ok", () {
- _addRecipe(passedRecipe: _removedRecipe);
- widget.redrawCallback!();
- });
+ widget.showToastCallback!("Added to Shoplist", "");
}
}
@@ -403,7 +375,7 @@ class _RecipeViewState extends State<RecipeView> {
PreferredSizeWidget _buildAppBar(BuildContext context, Recipe recipe) {
String _title = AppLocalizations.of(context)!.mode1;
- if (_isEditingAllowed()) _title = AppLocalizations.of(context)!.mode2;
+ if (_isEditModeEnabled) _title = AppLocalizations.of(context)!.mode2;
return AppBar(
title: Text(_title),
@@ -418,7 +390,7 @@ class _RecipeViewState extends State<RecipeView> {
}
Widget _buildAppBarCheckActions() {
- if (_isEditingAllowed()) {
+ if (_isEditModeEnabled) {
return IconButton(
icon: Icon(Icons.check),
onPressed: _addRecipe,
@@ -427,7 +399,7 @@ class _RecipeViewState extends State<RecipeView> {
return IconButton(
icon: Icon(Icons.edit),
onPressed: () {
- _readonlyOverride = true;
+ _isEditModeEnabled = true;
setState(() {});
},