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.readonly, required this.unsavedRecipe, required this.pickImageCallback, required this.removeImageCallback, required this.removeRecipeCallback, required this.downloadRecipeCallback, required this.isEditingAllowedCallback, required this.cacheUnsavedRecipeCallback, }) : super(key: key); final bool remote; final bool readonly; final Recipe unsavedRecipe; final Function pickImageCallback; final Function removeImageCallback; final Function removeRecipeCallback; final Function downloadRecipeCallback; final Function isEditingAllowedCallback; final Function cacheUnsavedRecipeCallback; @override _UtilityIconRowState createState() => _UtilityIconRowState(); } class _UtilityIconRowState extends State { 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.all(0), // EdgeInsets.only(left: 4.0), child: _buildButtonAddImage(), ), 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, ); } } */ }