Skip to content

Commit c52b69a

Browse files
committed
Update strings and refactor weight management
- Added new string constants for BMI and target weight in `StringsManager`. - Refactored `CustomAppBar` to conditionally display the back button based on navigation state. - Updated `WeightCubit` to simplify weight update logic. - Modified `WeightRulerSection` to use the new string constant for BMI label.
1 parent b6db570 commit c52b69a

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

lib/core/res/strings_manager.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,7 @@ abstract class AppStrings {
7474
static const String gallery = 'Gallery';
7575
static const String camera = 'Camera';
7676
static const String cancel = 'Cancel';
77+
static const String yourBmi = 'Your BMI';
78+
static const String yourTargetWeight = "What's your target weight?";
79+
7780
}

lib/core/widgets/custom_app_bar.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
66
final String? title;
77
final VoidCallback? onBack;
88
final List<Widget>? actions;
9-
final TextStyle?titleStyle;
9+
final TextStyle? titleStyle;
1010

1111
const CustomAppBar({
1212
super.key,
@@ -21,10 +21,13 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
2121
return AppBar(
2222
title: Text(title ?? '', style: titleStyle ?? StylesManager.regular18),
2323
centerTitle: true,
24-
leading: IconButton(
25-
icon: const Icon(Icons.arrow_back_ios_new_rounded),
26-
onPressed: onBack ?? () => context.pop(),
27-
),
24+
leading:
25+
context.canPop()
26+
? IconButton(
27+
icon: const Icon(Icons.arrow_back_ios_new_rounded),
28+
onPressed: onBack ?? () => context.pop(),
29+
)
30+
: null,
2831
elevation: 0,
2932
actions: actions,
3033
backgroundColor: Colors.transparent,

lib/features/trainee_measurements/presentation/cubits/weight/weight_cubit.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:graduation_project/features/trainee_measurements/domain/entities
44
import 'package:graduation_project/features/trainee_measurements/presentation/cubits/weight/weight_state.dart';
55
import 'package:injectable/injectable.dart';
66

7-
@injectable
7+
@lazySingleton
88
class WeightCubit extends Cubit<WeightState> {
99
final double _heightInCm;
1010
final Gender _gender;
@@ -13,9 +13,8 @@ class WeightCubit extends Cubit<WeightState> {
1313
: super(const WeightState());
1414

1515
void updateWeight(int value) {
16-
final weightInKg = state.isKg ? value.toDouble() : value / 2.20462;
17-
final bmi = _calculateBmi(weightInKg, _heightInCm);
18-
emit(state.copyWith(weight: weightInKg, bmi: bmi));
16+
final bmi = _calculateBmi(value.toDouble(), _heightInCm);
17+
emit(state.copyWith(weight: value.toDouble(), bmi: bmi));
1918
}
2019

2120
void toggleUnit(bool isKg) {

lib/features/trainee_measurements/presentation/widgets/weight/weight_picker_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WeightRulerSection extends StatelessWidget {
3838
const SizedBox(height: AppSize.s40),
3939
MeasurementFeedbackWidget(
4040
value: state.bmi.value.toStringAsFixed(1),
41-
label: 'Your BMI',
41+
label: AppStrings.yourBmi,
4242
status: state.bmi.category.displayName,
4343
message: cubit.bmiMessage,
4444
statusColor: state.bmi.category.color,

0 commit comments

Comments
 (0)