Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.
# This file should be version controlled and should not be manually edited.

version:
revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
channel: stable
revision: "35c388afb57ef061d06a39b537336c87e0e3d1b1"
channel: "[user-branch]"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
- platform: android
create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
- platform: ios
create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
create_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
base_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
- platform: web
create_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
base_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1

# User provided section

Expand Down
44 changes: 32 additions & 12 deletions lib/features/profile/presentation/widgets/set_height_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:horizontal_picker/horizontal_picker.dart';
import 'package:opennutritracker/generated/l10n.dart';

class SetHeightDialog extends StatelessWidget {
class SetHeightDialog extends StatefulWidget {
static const _heightRangeCM = 100.0;
static const _heightRangeFt = 10;
static const _heightRangeFt = 10.0;

final double userHeight;
final bool usesImperialUnits;
Expand All @@ -15,9 +15,29 @@ class SetHeightDialog extends StatelessWidget {
required this.usesImperialUnits,
});

@override
State<SetHeightDialog> createState() => _SetHeightDialogState();
}

class _SetHeightDialogState extends State<SetHeightDialog> {
late double selectedHeight;

@override
void initState() {
super.initState();
selectedHeight = widget.userHeight;
}

@override
Widget build(BuildContext context) {
double selectedHeight = userHeight;
final minValue = widget.usesImperialUnits
? widget.userHeight - SetHeightDialog._heightRangeFt
: widget.userHeight - SetHeightDialog._heightRangeCM;

final maxValue = widget.usesImperialUnits
? widget.userHeight + SetHeightDialog._heightRangeFt
: widget.userHeight + SetHeightDialog._heightRangeCM;

return AlertDialog(
title: Text(S.of(context).selectHeightDialogLabel),
content: Wrap(
Expand All @@ -27,18 +47,18 @@ class SetHeightDialog extends StatelessWidget {
HorizontalPicker(
height: 100,
backgroundColor: Colors.transparent,
minValue: usesImperialUnits
? selectedHeight - _heightRangeFt
: selectedHeight - _heightRangeCM,
maxValue: usesImperialUnits
? selectedHeight + _heightRangeFt
: selectedHeight + _heightRangeCM,
// Prevent negative minimum height
minValue: minValue < 0 ? 1 : minValue, // setting it to 1, because 0 triggers zero-division error
maxValue: maxValue,
divisions: 400,
suffix: usesImperialUnits
suffix: widget.usesImperialUnits
? S.of(context).ftLabel
: S.of(context).cmLabel,
onChanged: (value) {
selectedHeight = value;
setState(() {
// Prevent negative height values
selectedHeight = value < 0 ? 1 : value;
});
},
),
],
Expand All @@ -62,4 +82,4 @@ class SetHeightDialog extends StatelessWidget {
],
);
}
}
}
39 changes: 28 additions & 11 deletions lib/features/profile/presentation/widgets/set_weight_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:horizontal_picker/horizontal_picker.dart';
import 'package:opennutritracker/generated/l10n.dart';

class SetWeightDialog extends StatelessWidget {
class SetWeightDialog extends StatefulWidget {
static const weightRangeKg = 50.0;
static const weightRangeLbs = 100.0;

Expand All @@ -15,9 +15,29 @@ class SetWeightDialog extends StatelessWidget {
required this.usesImperialUnits,
});

@override
State<SetWeightDialog> createState() => _SetWeightDialogState();
}

class _SetWeightDialogState extends State<SetWeightDialog> {
late double selectedWeight;

@override
void initState() {
super.initState();
selectedWeight = widget.userWeight;
}

@override
Widget build(BuildContext context) {
double selectedWeight = userWeight;
final minValue = widget.usesImperialUnits
? widget.userWeight - SetWeightDialog.weightRangeLbs
: widget.userWeight - SetWeightDialog.weightRangeKg;

final maxValue = widget.usesImperialUnits
? widget.userWeight + SetWeightDialog.weightRangeLbs
: widget.userWeight + SetWeightDialog.weightRangeKg;

return AlertDialog(
title: Text(S.of(context).selectWeightDialogLabel),
content: Wrap(
Expand All @@ -27,19 +47,17 @@ class SetWeightDialog extends StatelessWidget {
HorizontalPicker(
height: 100,
backgroundColor: Colors.transparent,
minValue: usesImperialUnits
? userWeight - weightRangeLbs
: userWeight - weightRangeKg,
maxValue: usesImperialUnits
? userWeight + weightRangeLbs
: userWeight + weightRangeKg,
minValue: minValue < 0 ? 0 : minValue, // 👈 no negative minimum
maxValue: maxValue,
initialPosition: InitialPosition.center,
divisions: 1000,
suffix: usesImperialUnits
suffix: widget.usesImperialUnits
? S.of(context).lbsLabel
: S.of(context).kgLabel,
onChanged: (value) {
selectedWeight = value;
setState(() {
selectedWeight = value < 0 ? 0 : value; // 👈 no negative values
});
},
),
],
Expand All @@ -55,7 +73,6 @@ class SetWeightDialog extends StatelessWidget {
),
TextButton(
onPressed: () {
// TODO validate selected weight
Navigator.pop(context, selectedWeight);
},
child: Text(S.of(context).dialogOKLabel),
Expand Down
Loading