1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
import 'package:flutter/material.dart';
import 'package:kulinar_app/constants.dart';
import 'package:kulinar_app/models/data/settings_data_class.dart';
import 'package:kulinar_app/models/recipe_class.dart';
import 'package:kulinar_app/models/data/recipe_data_class.dart';
class UtilityIconRow extends StatefulWidget {
const UtilityIconRow({
Key? key,
this.remote = false,
required this.unsavedRecipe,
required this.isEditModeEnabled,
required this.pickImageCallback,
required this.removeImageCallback,
required this.removeRecipeCallback,
required this.downloadRecipeCallback,
required this.cacheUnsavedRecipeCallback,
}) : super(key: key);
final bool remote;
final bool isEditModeEnabled;
final Recipe unsavedRecipe;
final Function pickImageCallback;
final Function removeImageCallback;
final Function removeRecipeCallback;
final Function downloadRecipeCallback;
final Function cacheUnsavedRecipeCallback;
@override
_UtilityIconRowState createState() => _UtilityIconRowState();
}
class _UtilityIconRowState extends State<UtilityIconRow> {
bool _isInputSourceCamera = SettingsData.settings["photoSource"] == "0" ? true : false;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 6.0),
child: _buildButtonAddImage(),
),
Padding(
padding: const EdgeInsets.only(right: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
_buildIconRating(context),
_buildIconFavorite(),
// _buildIconCalculate(),
// _buildIconShare(),
// _buildIconImportExport(context),
],
),
),
],
),
);
}
IconButton _buildButtonAddImage() {
Icon _pickImageIcon;
Icon _removeImageIcon;
bool _recipeHasImage = widget.unsavedRecipe.image == null;
if (_isInputSourceCamera) {
_pickImageIcon = Icon(Icons.add_a_photo_rounded);
_removeImageIcon = Icon(Icons.no_photography_rounded);
} else {
_pickImageIcon = Icon(Icons.add_photo_alternate_rounded);
_removeImageIcon = Icon(Icons.image_not_supported_rounded);
}
void _onPress() {
if (_recipeHasImage) {
widget.pickImageCallback();
} else {
widget.removeImageCallback();
}
}
return IconButton(
icon: _recipeHasImage ? _pickImageIcon : _removeImageIcon,
onPressed: _onPress,
);
}
Widget _buildIconRating(BuildContext context) {
void _onPress() {
widget.unsavedRecipe.updateRating();
widget.cacheUnsavedRecipeCallback();
RecipeData.save();
setState(() {});
}
return Row(
children: [
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Text(widget.unsavedRecipe.rating.toString(), style: cDefaultTextStyle),
),
IconButton(
iconSize: 28.0,
icon: Icon(Icons.star_border_rounded),
onPressed: !widget.remote ? _onPress : null,
),
],
);
}
Widget _buildIconFavorite() {
Icon icon = Icon(Icons.favorite_border_rounded);
Color color = Colors.black;
if (widget.unsavedRecipe.favorite) {
icon = Icon(Icons.favorite_rounded);
color = Colors.red;
}
void _onPress() {
widget.unsavedRecipe.toggleFavorite();
widget.cacheUnsavedRecipeCallback();
RecipeData.save();
setState(() {});
}
return IconButton(
icon: icon,
color: color,
onPressed: !widget.remote ? _onPress : null,
);
}
/* todo: IMPLEMENT RICH TEXT https://stackoverflow.com/questions/41557139/how-do-i-bold-or-format-a-piece-of-text-within-a-paragraph
// todo: Implement recalculations (portions, measurement system)
Widget _buildIconCalculate() {
return IconButton(
icon: Icon(Icons.calculate_rounded),
onPressed: null,
);
}
*/
/* Widget _buildIconShare() {
return IconButton(
icon: Icon(Icons.share),
onPressed: widget.readonly && !widget.remote ? _shareData : null,
);
} */
/*
IF REMOTE:
DOWNLOAD
IF REMOTE AND LOCAL:
GO TO LOCAL
IF LOCAL:
UPLOAD
Widget _buildIconImportExport(BuildContext context) {
if (widget.unsavedRecipe.isListed(remote: true)) {
if (widget.unsavedRecipe.isListed()) {
return IconButton(
icon: Icon(Icons.get_app),
onPressed: !widget.isEditingAllowedCallback() ? () => widget.downloadRecipeCallback(context, widget.unsavedRecipe) : null,
);
} else {
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: !widget.isEditingAllowedCallback() ? () => widget.downloadRecipeCallback(context, widget.unsavedRecipe) : null,
);
}
} else {
return IconButton(
icon: Icon(Icons.publish),
onPressed: !widget.isEditingAllowedCallback() ? () => _uploadRecipe(context) : null,
);
}
}
*/
}
|