2021-10-22 23:08:09 +00:00
|
|
|
import 'package:diameter/components/detail.dart';
|
|
|
|
import 'package:diameter/components/dialogs.dart';
|
2021-11-24 23:19:27 +00:00
|
|
|
import 'package:diameter/components/dropdown.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:diameter/components/forms.dart';
|
|
|
|
import 'package:diameter/models/accuracy.dart';
|
|
|
|
import 'package:diameter/models/log_meal.dart';
|
|
|
|
import 'package:diameter/models/meal.dart';
|
|
|
|
import 'package:diameter/models/meal_category.dart';
|
|
|
|
import 'package:diameter/models/meal_portion_type.dart';
|
|
|
|
import 'package:diameter/models/meal_source.dart';
|
2021-12-04 23:44:46 +00:00
|
|
|
import 'package:diameter/models/settings.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:diameter/navigation.dart';
|
2021-12-09 05:14:55 +00:00
|
|
|
import 'package:diameter/screens/accuracy_detail.dart';
|
|
|
|
import 'package:diameter/screens/meal/meal_category_detail.dart';
|
|
|
|
import 'package:diameter/screens/meal/meal_detail.dart';
|
|
|
|
import 'package:diameter/screens/meal/meal_portion_type_detail.dart';
|
|
|
|
import 'package:diameter/screens/meal/meal_source_detail.dart';
|
2021-10-24 21:53:44 +00:00
|
|
|
import 'package:diameter/utils/utils.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class LogMealDetailScreen extends StatefulWidget {
|
|
|
|
static const String routeName = '/log-meal';
|
2021-11-24 23:19:27 +00:00
|
|
|
|
|
|
|
final int logEntryId;
|
|
|
|
final int id;
|
|
|
|
|
|
|
|
const LogMealDetailScreen({Key? key, this.logEntryId = 0, this.id = 0})
|
2021-10-22 23:08:09 +00:00
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_LogMealDetailScreenState createState() => _LogMealDetailScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LogMealDetailScreenState extends State<LogMealDetailScreen> {
|
2021-11-24 23:19:27 +00:00
|
|
|
LogMeal? _logMeal;
|
|
|
|
bool _isNew = true;
|
|
|
|
bool _isSaving = false;
|
2021-12-09 05:14:55 +00:00
|
|
|
bool _isExpanded = false;
|
2021-11-24 23:19:27 +00:00
|
|
|
|
2021-12-11 01:30:46 +00:00
|
|
|
double _amount = 1;
|
|
|
|
|
2021-10-22 23:08:09 +00:00
|
|
|
final GlobalKey<FormState> _logMealForm = GlobalKey<FormState>();
|
2021-12-09 05:14:55 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2021-11-07 20:13:28 +00:00
|
|
|
|
2021-10-22 23:08:09 +00:00
|
|
|
final _valueController = TextEditingController(text: '');
|
2021-12-11 01:30:46 +00:00
|
|
|
final _amountController = TextEditingController(text: '');
|
2021-10-22 23:08:09 +00:00
|
|
|
final _carbsRatioController = TextEditingController(text: '');
|
|
|
|
final _portionSizeController = TextEditingController(text: '');
|
2021-12-11 01:30:46 +00:00
|
|
|
final _totalCarbsController = TextEditingController(text: '');
|
2021-10-22 23:08:09 +00:00
|
|
|
final _notesController = TextEditingController(text: '');
|
2021-11-24 23:19:27 +00:00
|
|
|
|
2021-11-07 20:13:28 +00:00
|
|
|
Meal? _meal;
|
|
|
|
MealSource? _mealSource;
|
|
|
|
MealCategory? _mealCategory;
|
|
|
|
MealPortionType? _mealPortionType;
|
|
|
|
Accuracy? _portionSizeAccuracy;
|
|
|
|
Accuracy? _carbsRatioAccuracy;
|
2021-10-22 23:08:09 +00:00
|
|
|
|
2021-12-09 05:14:55 +00:00
|
|
|
final _mealController = TextEditingController(text: '');
|
|
|
|
final _mealSourceController = TextEditingController(text: '');
|
|
|
|
final _mealCategoryController = TextEditingController(text: '');
|
|
|
|
final _mealPortionTypeController = TextEditingController(text: '');
|
|
|
|
final _portionSizeAccuracyController = TextEditingController(text: '');
|
|
|
|
final _carbsRatioAccuracyController = TextEditingController(text: '');
|
|
|
|
|
2021-11-07 20:13:28 +00:00
|
|
|
List<Meal> _meals = [];
|
|
|
|
List<MealCategory> _mealCategories = [];
|
|
|
|
List<MealPortionType> _mealPortionTypes = [];
|
|
|
|
List<MealSource> _mealSources = [];
|
|
|
|
List<Accuracy> _portionSizeAccuracies = [];
|
|
|
|
List<Accuracy> _carbsRatioAccuracies = [];
|
2021-10-22 23:08:09 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-11-24 23:19:27 +00:00
|
|
|
reload();
|
2021-10-22 23:08:09 +00:00
|
|
|
|
2021-11-07 20:13:28 +00:00
|
|
|
_portionSizeAccuracies = Accuracy.getAllForPortionSize();
|
|
|
|
_carbsRatioAccuracies = Accuracy.getAllForCarbsRatio();
|
|
|
|
_meals = Meal.getAll();
|
|
|
|
_mealCategories = MealCategory.getAll();
|
|
|
|
_mealPortionTypes = MealPortionType.getAll();
|
|
|
|
_mealSources = MealSource.getAll();
|
|
|
|
|
2021-11-24 23:19:27 +00:00
|
|
|
if (widget.id != 0) {
|
|
|
|
_valueController.text = _logMeal!.value;
|
2021-12-11 01:30:46 +00:00
|
|
|
_amountController.text = _logMeal!.amount.toString();
|
2021-11-24 23:19:27 +00:00
|
|
|
_carbsRatioController.text = (_logMeal!.carbsRatio ?? '').toString();
|
|
|
|
_portionSizeController.text = (_logMeal!.portionSize ?? '').toString();
|
2021-12-11 01:30:46 +00:00
|
|
|
_totalCarbsController.text = (_logMeal!.totalCarbs ?? '').toString();
|
2021-11-24 23:19:27 +00:00
|
|
|
_notesController.text = _logMeal!.notes ?? '';
|
2021-12-09 05:14:55 +00:00
|
|
|
|
|
|
|
_meal = _logMeal!.meal.target;
|
|
|
|
_mealController.text = (_meal ?? '').toString();
|
|
|
|
_mealSource = _logMeal!.mealSource.target;
|
|
|
|
_mealSourceController.text = (_mealSource ?? '').toString();
|
|
|
|
_mealCategory = _logMeal!.mealCategory.target;
|
|
|
|
_mealCategoryController.text = (_mealCategory ?? '').toString();
|
|
|
|
_mealPortionType = _logMeal!.mealPortionType.target;
|
|
|
|
_mealPortionTypeController.text = (_mealPortionType ?? '').toString();
|
|
|
|
_portionSizeAccuracy = _logMeal!.portionSizeAccuracy.target;
|
|
|
|
_portionSizeAccuracyController.text =
|
|
|
|
(_portionSizeAccuracy ?? '').toString();
|
|
|
|
_carbsRatioAccuracy = _logMeal!.carbsRatioAccuracy.target;
|
|
|
|
_carbsRatioAccuracyController.text =
|
|
|
|
(_carbsRatioAccuracy ?? '').toString();
|
2021-11-24 23:19:27 +00:00
|
|
|
}
|
2021-12-11 01:30:46 +00:00
|
|
|
|
|
|
|
if (_amountController.text == '') {
|
|
|
|
_amountController.text = '1';
|
|
|
|
}
|
2021-11-24 23:19:27 +00:00
|
|
|
}
|
2021-10-22 23:08:09 +00:00
|
|
|
|
2021-12-09 05:14:55 +00:00
|
|
|
void reload({String? message}) {
|
2021-11-24 23:19:27 +00:00
|
|
|
if (widget.id != 0) {
|
|
|
|
setState(() {
|
|
|
|
_logMeal = LogMeal.get(widget.id);
|
|
|
|
});
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
2021-11-24 23:19:27 +00:00
|
|
|
_isNew = _logMeal == null;
|
2021-12-09 05:14:55 +00:00
|
|
|
|
|
|
|
setState(() {
|
|
|
|
if (message != null) {
|
|
|
|
var snackBar = SnackBar(
|
|
|
|
content: Text(message),
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
);
|
|
|
|
ScaffoldMessenger.of(context)
|
|
|
|
..removeCurrentSnackBar()
|
|
|
|
..showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateCarbsRatioAccuracy(Accuracy? value) {
|
|
|
|
setState(() {
|
|
|
|
_carbsRatioAccuracy = value;
|
|
|
|
_carbsRatioAccuracyController.text =
|
|
|
|
(_carbsRatioAccuracy ?? '').toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updatePortionSizeAccuracy(Accuracy? value) {
|
|
|
|
setState(() {
|
|
|
|
_portionSizeAccuracy = value;
|
|
|
|
_portionSizeAccuracyController.text =
|
|
|
|
(_portionSizeAccuracy ?? '').toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateMealCategory(MealCategory? value) {
|
|
|
|
setState(() {
|
|
|
|
_mealCategory = value;
|
|
|
|
_mealCategoryController.text = (_mealCategory ?? '').toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateMealPortionType(MealPortionType? value) {
|
|
|
|
setState(() {
|
|
|
|
_mealPortionType = value;
|
|
|
|
_mealPortionTypeController.text = (_mealPortionType ?? '').toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateMealSource(MealSource? value) {
|
|
|
|
setState(() {
|
|
|
|
_mealSource = value;
|
|
|
|
_mealSourceController.text = (_mealSource ?? '').toString();
|
|
|
|
});
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 05:14:55 +00:00
|
|
|
Future<void> onSelectMeal(Meal? meal) async {
|
2021-11-07 20:13:28 +00:00
|
|
|
setState(() {
|
|
|
|
_meal = meal;
|
2021-12-11 01:30:46 +00:00
|
|
|
_mealController.text = (_meal ?? '').toString();
|
|
|
|
_valueController.text = _mealController.text;
|
|
|
|
_carbsRatioController.text = (meal?.carbsRatio ?? '').toString();
|
|
|
|
_amountController.text = '1';
|
|
|
|
_portionSizeController.text = (meal?.portionSize ?? '').toString();
|
|
|
|
_totalCarbsController.text = (meal?.carbsPerPortion ?? '').toString();
|
2021-12-09 05:14:55 +00:00
|
|
|
});
|
2021-12-11 01:30:46 +00:00
|
|
|
updateMealSource(meal?.mealSource.target);
|
|
|
|
updateMealCategory(meal?.mealCategory.target);
|
|
|
|
updateMealPortionType(meal?.mealPortionType.target);
|
|
|
|
updatePortionSizeAccuracy(meal?.portionSizeAccuracy.target);
|
|
|
|
updateCarbsRatioAccuracy(meal?.carbsRatioAccuracy.target);
|
2021-10-24 21:53:44 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 23:08:09 +00:00
|
|
|
void handleSaveAction() async {
|
2021-10-27 19:00:28 +00:00
|
|
|
setState(() {
|
|
|
|
_isSaving = true;
|
|
|
|
});
|
2021-10-22 23:08:09 +00:00
|
|
|
if (_logMealForm.currentState!.validate()) {
|
2021-11-07 20:13:28 +00:00
|
|
|
LogMeal logMeal = LogMeal(
|
2021-11-24 23:19:27 +00:00
|
|
|
id: widget.id,
|
2021-11-07 20:13:28 +00:00
|
|
|
value: _valueController.text,
|
|
|
|
carbsRatio: double.tryParse(_carbsRatioController.text),
|
|
|
|
portionSize: double.tryParse(_portionSizeController.text),
|
2021-12-11 01:30:46 +00:00
|
|
|
totalCarbs: double.tryParse(_totalCarbsController.text),
|
2021-11-07 20:13:28 +00:00
|
|
|
);
|
2021-11-25 18:25:13 +00:00
|
|
|
logMeal.logEntry.targetId = widget.logEntryId;
|
2021-11-07 20:13:28 +00:00
|
|
|
logMeal.meal.target = _meal;
|
|
|
|
logMeal.mealSource.target = _mealSource;
|
|
|
|
logMeal.mealCategory.target = _mealCategory;
|
|
|
|
logMeal.mealPortionType.target = _mealPortionType;
|
|
|
|
logMeal.portionSizeAccuracy.target = _portionSizeAccuracy;
|
|
|
|
logMeal.carbsRatioAccuracy.target = _carbsRatioAccuracy;
|
2021-11-24 23:19:27 +00:00
|
|
|
|
2021-11-07 20:13:28 +00:00
|
|
|
LogMeal.put(logMeal);
|
2021-12-09 05:14:55 +00:00
|
|
|
Navigator.pop(context, ['${_isNew ? 'New' : ''} Meal Saved', logMeal]);
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
2021-10-27 19:00:28 +00:00
|
|
|
setState(() {
|
|
|
|
_isSaving = false;
|
|
|
|
});
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleCancelAction() {
|
2021-12-04 23:44:46 +00:00
|
|
|
if (Settings.get().showConfirmationDialogOnCancel &&
|
2021-11-24 23:19:27 +00:00
|
|
|
((_isNew &&
|
2021-10-22 23:08:09 +00:00
|
|
|
(_valueController.text != '' ||
|
|
|
|
_meal != null ||
|
2021-11-07 20:13:28 +00:00
|
|
|
_mealSource != null ||
|
|
|
|
_mealCategory != null ||
|
|
|
|
_mealPortionType != null ||
|
2021-10-22 23:08:09 +00:00
|
|
|
double.tryParse(_carbsRatioController.text) != null ||
|
|
|
|
double.tryParse(_portionSizeController.text) != null ||
|
2021-12-11 01:30:46 +00:00
|
|
|
double.tryParse(_totalCarbsController.text) != null ||
|
2021-10-22 23:08:09 +00:00
|
|
|
_carbsRatioAccuracy != null ||
|
|
|
|
_portionSizeAccuracy != null ||
|
|
|
|
_notesController.text != '')) ||
|
2021-11-24 23:19:27 +00:00
|
|
|
(!_isNew &&
|
|
|
|
(_valueController.text != _logMeal!.value ||
|
|
|
|
_meal != _logMeal!.meal.target ||
|
|
|
|
_mealSource != _logMeal!.mealSource.target ||
|
|
|
|
_mealCategory != _logMeal!.mealCategory.target ||
|
|
|
|
_mealPortionType != _logMeal!.mealPortionType.target ||
|
2021-10-22 23:08:09 +00:00
|
|
|
double.tryParse(_carbsRatioController.text) !=
|
2021-11-24 23:19:27 +00:00
|
|
|
_logMeal!.carbsRatio ||
|
2021-10-22 23:08:09 +00:00
|
|
|
double.tryParse(_portionSizeController.text) !=
|
2021-11-24 23:19:27 +00:00
|
|
|
_logMeal!.portionSize ||
|
2021-12-11 01:30:46 +00:00
|
|
|
double.tryParse(_totalCarbsController.text) !=
|
|
|
|
_logMeal!.totalCarbs ||
|
2021-11-07 20:13:28 +00:00
|
|
|
_carbsRatioAccuracy !=
|
2021-11-24 23:19:27 +00:00
|
|
|
_logMeal!.carbsRatioAccuracy.target ||
|
2021-10-22 23:08:09 +00:00
|
|
|
_portionSizeAccuracy !=
|
2021-11-24 23:19:27 +00:00
|
|
|
_logMeal!.portionSizeAccuracy.target ||
|
|
|
|
_notesController.text != (_logMeal!.notes ?? ''))))) {
|
2021-10-22 23:08:09 +00:00
|
|
|
Dialogs.showCancelConfirmationDialog(
|
|
|
|
context: context,
|
2021-11-24 23:19:27 +00:00
|
|
|
isNew: _isNew,
|
2021-10-22 23:08:09 +00:00
|
|
|
onSave: handleSaveAction,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 01:30:46 +00:00
|
|
|
void updateAmount(double? amount) {
|
|
|
|
double? previousAmount;
|
|
|
|
double? portionSize;
|
|
|
|
double? carbsRatio;
|
|
|
|
|
|
|
|
previousAmount = _amount;
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_amountController.text = (amount ?? '').toString();
|
|
|
|
_amount = amount ?? 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (_carbsRatioController.text != '') {
|
|
|
|
carbsRatio = double.tryParse(_carbsRatioController.text);
|
|
|
|
}
|
|
|
|
if (_portionSizeController.text != '') {
|
|
|
|
portionSize = double.tryParse(_portionSizeController.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amount != null && portionSize != null) {
|
|
|
|
setState(() {
|
|
|
|
portionSize = portionSize! / (previousAmount ?? 1) * amount;
|
|
|
|
_portionSizeController.text = portionSize.toString();
|
|
|
|
});
|
|
|
|
if (carbsRatio != null) {
|
|
|
|
setState(() {
|
|
|
|
_totalCarbsController.text =
|
|
|
|
Utils.calculateCarbs(carbsRatio!, portionSize!).toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void calculateThirdMeasurementOfPortionCarbsRelation() {
|
|
|
|
int? amount;
|
2021-10-24 21:53:44 +00:00
|
|
|
double? carbsRatio;
|
|
|
|
double? portionSize;
|
|
|
|
double? carbsPerPortion;
|
|
|
|
|
2021-12-11 01:30:46 +00:00
|
|
|
if (_amountController.text != '') {
|
|
|
|
amount = int.tryParse(_amountController.text);
|
|
|
|
}
|
|
|
|
if (_carbsRatioController.text != '') {
|
2021-10-24 21:53:44 +00:00
|
|
|
carbsRatio = double.tryParse(_carbsRatioController.text);
|
|
|
|
}
|
2021-12-11 01:30:46 +00:00
|
|
|
if (_portionSizeController.text != '') {
|
2021-10-24 21:53:44 +00:00
|
|
|
portionSize = double.tryParse(_portionSizeController.text);
|
|
|
|
}
|
2021-12-11 01:30:46 +00:00
|
|
|
if (_totalCarbsController.text != '') {
|
|
|
|
carbsPerPortion = double.tryParse(_totalCarbsController.text);
|
2021-10-24 21:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (carbsRatio != null && portionSize != null && carbsPerPortion == null) {
|
|
|
|
setState(() {
|
2021-12-11 01:30:46 +00:00
|
|
|
_totalCarbsController.text =
|
|
|
|
Utils.calculateCarbs(carbsRatio!, portionSize! * (amount ?? 1))
|
2021-10-24 21:53:44 +00:00
|
|
|
.toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (carbsRatio == null && portionSize != null && carbsPerPortion != null) {
|
|
|
|
setState(() {
|
2021-12-11 01:30:46 +00:00
|
|
|
_carbsRatioController.text = Utils.calculateCarbsRatio(
|
|
|
|
carbsPerPortion!, portionSize! * (amount ?? 1))
|
|
|
|
.toString();
|
2021-10-24 21:53:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (carbsRatio != null && portionSize == null && carbsPerPortion != null) {
|
|
|
|
setState(() {
|
|
|
|
_portionSizeController.text =
|
|
|
|
Utils.calculatePortionSize(carbsRatio!, carbsPerPortion!)
|
|
|
|
.toString();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 23:08:09 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-12-11 01:30:46 +00:00
|
|
|
title: Text(_isNew ? 'New Meal for Log Entry' : _logMeal!.value),
|
2021-10-22 23:08:09 +00:00
|
|
|
),
|
|
|
|
drawer: const Navigation(currentLocation: LogMealDetailScreen.routeName),
|
2021-12-09 05:14:55 +00:00
|
|
|
body: Scrollbar(
|
|
|
|
controller: _scrollController,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
controller: _scrollController,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
FormWrapper(
|
|
|
|
formState: _logMealForm,
|
|
|
|
fields: [
|
|
|
|
TextFormField(
|
|
|
|
controller: _valueController,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Name',
|
|
|
|
),
|
|
|
|
validator: (value) {
|
|
|
|
if (value!.trim().isEmpty) {
|
|
|
|
return 'Empty name';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2021-10-22 23:08:09 +00:00
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: AutoCompleteDropdownButton<Meal>(
|
|
|
|
controller: _mealController,
|
|
|
|
selectedItem: _meal,
|
|
|
|
label: 'Meal',
|
|
|
|
items: _meals,
|
2021-12-11 01:30:46 +00:00
|
|
|
onChanged: onSelectMeal,
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => _meal == null
|
|
|
|
? const MealDetailScreen()
|
|
|
|
: MealDetailScreen(id: _meal!.id),
|
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
onSelectMeal(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
2021-12-06 22:09:40 +00:00
|
|
|
},
|
2021-12-09 05:14:55 +00:00
|
|
|
icon: Icon(_meal == null ? Icons.add : Icons.edit),
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
],
|
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
NumberFormField(
|
|
|
|
controller: _amountController,
|
|
|
|
label: 'Amount',
|
|
|
|
suffix: _mealPortionType?.value,
|
2021-12-11 21:02:35 +00:00
|
|
|
min: 0,
|
2021-12-11 01:30:46 +00:00
|
|
|
onChanged: updateAmount,
|
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextFormField(
|
2021-12-11 01:30:46 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Portion size',
|
|
|
|
suffixText: Settings.nutritionMeasurementSuffix,
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
controller: _portionSizeController,
|
2021-12-09 05:14:55 +00:00
|
|
|
keyboardType: const TextInputType.numberWithOptions(
|
|
|
|
decimal: true),
|
|
|
|
onChanged: (_) async {
|
|
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
|
|
calculateThirdMeasurementOfPortionCarbsRelation();
|
|
|
|
},
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
const SizedBox(width: 10),
|
2021-12-09 05:14:55 +00:00
|
|
|
Expanded(
|
|
|
|
child: TextFormField(
|
2021-12-11 01:30:46 +00:00
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Carbs ratio',
|
|
|
|
suffixText: '%',
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
controller: _carbsRatioController,
|
2021-12-09 05:14:55 +00:00
|
|
|
keyboardType: const TextInputType.numberWithOptions(
|
|
|
|
decimal: true),
|
|
|
|
onChanged: (_) async {
|
|
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
|
|
calculateThirdMeasurementOfPortionCarbsRelation();
|
|
|
|
},
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
const SizedBox(width: 10),
|
2021-12-09 05:14:55 +00:00
|
|
|
Expanded(
|
|
|
|
child: TextFormField(
|
|
|
|
decoration: InputDecoration(
|
2021-12-11 01:30:46 +00:00
|
|
|
labelText: 'Total carbs',
|
2021-12-09 05:14:55 +00:00
|
|
|
suffixText: Settings.nutritionMeasurementSuffix,
|
|
|
|
),
|
2021-12-11 01:30:46 +00:00
|
|
|
controller: _totalCarbsController,
|
2021-12-09 05:14:55 +00:00
|
|
|
keyboardType: const TextInputType.numberWithOptions(
|
|
|
|
decimal: true),
|
|
|
|
onChanged: (_) async {
|
|
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
|
|
calculateThirdMeasurementOfPortionCarbsRelation();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
TextFormField(
|
|
|
|
controller: _notesController,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Notes',
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
minLines: 2,
|
|
|
|
maxLines: 5,
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () => setState(() {
|
|
|
|
_isExpanded = !_isExpanded;
|
|
|
|
}),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'ADDITIONAL FIELDS',
|
|
|
|
style: Theme.of(context).textTheme.subtitle2,
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
Icon(_isExpanded
|
|
|
|
? Icons.expand_less
|
|
|
|
: Icons.expand_more),
|
|
|
|
],
|
2021-10-24 21:53:44 +00:00
|
|
|
),
|
2021-10-22 23:08:09 +00:00
|
|
|
),
|
2021-12-09 05:14:55 +00:00
|
|
|
Column(
|
|
|
|
children: _isExpanded
|
|
|
|
? [
|
|
|
|
Padding(
|
2021-12-11 01:30:46 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 5.0),
|
2021-12-09 05:14:55 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2021-12-11 01:30:46 +00:00
|
|
|
child:
|
|
|
|
AutoCompleteDropdownButton<MealSource>(
|
2021-12-09 05:14:55 +00:00
|
|
|
controller: _mealSourceController,
|
|
|
|
selectedItem: _mealSource,
|
|
|
|
label: 'Meal Source',
|
|
|
|
items: _mealSources,
|
|
|
|
onChanged: updateMealSource,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2021-12-11 01:30:46 +00:00
|
|
|
builder: (context) => _mealSource ==
|
|
|
|
null
|
|
|
|
? const MealSourceDetailScreen()
|
|
|
|
: MealSourceDetailScreen(
|
|
|
|
id: _mealSource!.id),
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
updateMealSource(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Icon(_mealSource == null
|
|
|
|
? Icons.add
|
|
|
|
: Icons.edit),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2021-12-11 01:30:46 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 5.0),
|
2021-12-09 05:14:55 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2021-12-11 01:30:46 +00:00
|
|
|
child: AutoCompleteDropdownButton<
|
|
|
|
MealCategory>(
|
2021-12-09 05:14:55 +00:00
|
|
|
controller: _mealCategoryController,
|
|
|
|
selectedItem: _mealCategory,
|
|
|
|
label: 'Meal Category',
|
|
|
|
items: _mealCategories,
|
|
|
|
onChanged: updateMealCategory,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => _mealCategory ==
|
|
|
|
null
|
|
|
|
? const MealCategoryDetailScreen()
|
|
|
|
: MealCategoryDetailScreen(
|
|
|
|
id: _mealCategory!.id),
|
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
updateMealCategory(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Icon(_mealCategory == null
|
|
|
|
? Icons.add
|
|
|
|
: Icons.edit),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2021-12-11 01:30:46 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 5.0),
|
2021-12-09 05:14:55 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: AutoCompleteDropdownButton<
|
|
|
|
MealPortionType>(
|
|
|
|
controller: _mealPortionTypeController,
|
|
|
|
selectedItem: _mealPortionType,
|
|
|
|
label: 'Meal Portion Type',
|
|
|
|
items: _mealPortionTypes,
|
|
|
|
onChanged: updateMealPortionType,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => _mealPortionType ==
|
|
|
|
null
|
|
|
|
? const MealPortionTypeDetailScreen()
|
|
|
|
: MealPortionTypeDetailScreen(
|
|
|
|
id: _mealPortionType!.id),
|
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
updateMealPortionType(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Icon(_mealPortionType == null
|
|
|
|
? Icons.add
|
|
|
|
: Icons.edit),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2021-12-11 01:30:46 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 5.0),
|
2021-12-09 05:14:55 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: AutoCompleteDropdownButton<Accuracy>(
|
2021-12-11 01:30:46 +00:00
|
|
|
controller:
|
|
|
|
_portionSizeAccuracyController,
|
2021-12-09 05:14:55 +00:00
|
|
|
selectedItem: _portionSizeAccuracy,
|
|
|
|
label: 'Portion Size Accuracy',
|
|
|
|
items: _portionSizeAccuracies,
|
|
|
|
onChanged: updatePortionSizeAccuracy,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2021-12-11 01:30:46 +00:00
|
|
|
builder: (context) =>
|
|
|
|
_portionSizeAccuracy == null
|
|
|
|
? const AccuracyDetailScreen()
|
|
|
|
: AccuracyDetailScreen(
|
|
|
|
id: _portionSizeAccuracy!
|
|
|
|
.id),
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
updatePortionSizeAccuracy(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Icon(_portionSizeAccuracy == null
|
|
|
|
? Icons.add
|
|
|
|
: Icons.edit),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2021-12-11 01:30:46 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 5.0),
|
2021-12-09 05:14:55 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: AutoCompleteDropdownButton<Accuracy>(
|
|
|
|
controller: _carbsRatioAccuracyController,
|
|
|
|
selectedItem: _carbsRatioAccuracy,
|
|
|
|
label: 'Carbs Ratio Accuracy',
|
|
|
|
items: _carbsRatioAccuracies,
|
|
|
|
onChanged: updateCarbsRatioAccuracy,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2021-12-11 01:30:46 +00:00
|
|
|
builder: (context) =>
|
|
|
|
_carbsRatioAccuracy == null
|
|
|
|
? const AccuracyDetailScreen()
|
|
|
|
: AccuracyDetailScreen(
|
|
|
|
id: _carbsRatioAccuracy!
|
|
|
|
.id),
|
2021-12-09 05:14:55 +00:00
|
|
|
),
|
|
|
|
).then((result) {
|
|
|
|
updateCarbsRatioAccuracy(result?[1]);
|
|
|
|
reload(message: result?[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Icon(_carbsRatioAccuracy == null
|
|
|
|
? Icons.add
|
|
|
|
: Icons.edit),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: [],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-10-22 23:08:09 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
bottomNavigationBar: DetailBottomRow(
|
|
|
|
onCancel: handleCancelAction,
|
2021-12-10 05:42:20 +00:00
|
|
|
onAction: _isSaving ? null : handleSaveAction,
|
2021-10-22 23:08:09 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|