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: 17 additions & 2 deletions lib/features/onboarding/onboarding_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
image: _defaultImageWidget,
bodyWidget: OnboardingIntroPageBody(
setPageContent: _setIntroPageData,
initialAcceptedPolicy: _introPageButtonActive,
initialAcceptedDataCollection: _onboardingBloc.userSelection.acceptDataCollection,
),
footer: HighlightButton(
buttonLabel: S.of(context).buttonStartLabel,
Expand All @@ -113,6 +115,9 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
image: _defaultImageWidget,
bodyWidget: OnboardingFirstPageBody(
setPageContent: _setFirstPageData,
initiallySelectedDate: _onboardingBloc.userSelection.birthday,
initialMaleSelected: _onboardingBloc.userSelection.gender == UserGenderSelectionEntity.genderMale,
initialFemaleSelected: _onboardingBloc.userSelection.gender == UserGenderSelectionEntity.genderFemale,
),
footer: HighlightButton(
buttonLabel: S.of(context).buttonNextLabel,
Expand All @@ -121,24 +126,31 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
)),
PageViewModel(
titleWidget: const SizedBox(),
// empty
decoration: _pageDecoration,
image: _defaultImageWidget,
bodyWidget: OnboardingSecondPageBody(
setButtonContent: _setSecondPageData,
initialHeight: _onboardingBloc.userSelection.height,
initialWeight: _onboardingBloc.userSelection.weight,
initialUsesImperial: _onboardingBloc.userSelection.usesImperialUnits,
),
footer: HighlightButton(
buttonLabel: S.of(context).buttonNextLabel,
onButtonPressed: () => _scrollToPage(3),
buttonActive: _secondPageButtonActive,
)),
),
),
PageViewModel(
titleWidget: const SizedBox(),
// empty
decoration: _pageDecoration,
image: _defaultImageWidget,
bodyWidget: OnboardingThirdPageBody(
setButtonContent: _setThirdPageButton,
initialSedentarySelected: _onboardingBloc.userSelection.activity == UserActivitySelectionEntity.sedentary,
initialLowActiveSelected: _onboardingBloc.userSelection.activity == UserActivitySelectionEntity.lowActive,
initialActiveSelected: _onboardingBloc.userSelection.activity == UserActivitySelectionEntity.active,
initialVeryActiveSelected: _onboardingBloc.userSelection.activity == UserActivitySelectionEntity.veryActive,
),
footer: HighlightButton(
buttonLabel: S.of(context).buttonNextLabel,
Expand All @@ -152,6 +164,9 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
image: _defaultImageWidget,
bodyWidget: OnboardingFourthPageBody(
setButtonContent: _setFourthPageButton,
initiallyLooseWeightSelected: _onboardingBloc.userSelection.goal == UserGoalSelectionEntity.loseWeight,
initiallyMaintainWeightSelected: _onboardingBloc.userSelection.goal == UserGoalSelectionEntity.maintainWeight,
initiallyGainWeightSelected: _onboardingBloc.userSelection.goal == UserGoalSelectionEntity.gainWeigh,
),
footer: HighlightButton(
buttonLabel: S.of(context).buttonNextLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import 'package:opennutritracker/generated/l10n.dart';
import 'package:url_launcher/url_launcher.dart';

class OnboardingIntroPageBody extends StatefulWidget {
const OnboardingIntroPageBody({super.key, required this.setPageContent});

final Function(bool active, bool acceptedDataCollection) setPageContent;

final bool initialAcceptedPolicy;
final bool initialAcceptedDataCollection;

const OnboardingIntroPageBody({
super.key,
required this.setPageContent,
this.initialAcceptedPolicy = false,
this.initialAcceptedDataCollection = false
});
@override
State<OnboardingIntroPageBody> createState() =>
_OnboardingIntroPageBodyState();
Expand All @@ -20,6 +27,13 @@ class _OnboardingIntroPageBodyState extends State<OnboardingIntroPageBody> {
bool _acceptedPolicy = false;
bool _acceptedDataCollection = false;

@override
void initState() {
super.initState();
_acceptedPolicy = widget.initialAcceptedPolicy;
_acceptedDataCollection = widget.initialAcceptedDataCollection;
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ class OnboardingFirstPageBody extends StatefulWidget {
bool active, UserGenderSelectionEntity? gender, DateTime? birthday)
setPageContent;

const OnboardingFirstPageBody({super.key, required this.setPageContent});
final DateTime? initiallySelectedDate;
final bool initialMaleSelected;
final bool initialFemaleSelected;

const OnboardingFirstPageBody({
super.key,
required this.setPageContent,
this.initiallySelectedDate,
this.initialMaleSelected = false,
this.initialFemaleSelected = false
});

@override
State<OnboardingFirstPageBody> createState() =>
Expand All @@ -22,6 +32,15 @@ class _OnboardingFirstPageBodyState extends State<OnboardingFirstPageBody> {
bool _maleSelected = false;
bool _femaleSelected = false;

@override
void initState() {
super.initState();
_selectedDate = widget.initiallySelectedDate;
_maleSelected = widget.initialMaleSelected;
_femaleSelected = widget.initialFemaleSelected;
_selectedDate != null ? _dateInput.text = DateFormat('yyyy-MM-dd').format(_selectedDate!) : null;
}

@override
Widget build(BuildContext context) {
return SizedBox(
Expand Down Expand Up @@ -86,7 +105,7 @@ class _OnboardingFirstPageBodyState extends State<OnboardingFirstPageBody> {
void onDateInputClicked() async {
final pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
initialDate: _selectedDate ?? DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime(2100));
if (pickedDate != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ class OnboardingFourthPageBody extends StatefulWidget {
final Function(bool active, UserGoalSelectionEntity? selectedGoal)
setButtonContent;

const OnboardingFourthPageBody({super.key, required this.setButtonContent});
final bool initiallyLooseWeightSelected;
final bool initiallyMaintainWeightSelected;
final bool initiallyGainWeightSelected;

const OnboardingFourthPageBody({
super.key,
required this.setButtonContent,
this.initiallyLooseWeightSelected = false,
this.initiallyMaintainWeightSelected = false,
this.initiallyGainWeightSelected = false
});

@override
State<OnboardingFourthPageBody> createState() =>
Expand All @@ -18,6 +28,14 @@ class _OnboardingFourthPageBodyState extends State<OnboardingFourthPageBody> {
bool _maintainWeightSelected = false;
bool _gainWeightSelected = false;

@override
void initState() {
super.initState();
_looseWeightSelected = widget.initiallyLooseWeightSelected;
_maintainWeightSelected = widget.initiallyMaintainWeightSelected;
_gainWeightSelected = widget.initiallyGainWeightSelected;
}

@override
Widget build(BuildContext context) {
return SizedBox(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ class OnboardingSecondPageBody extends StatefulWidget {
final Function(bool active, double? selectedHeight, double? selectedWeight,
bool usesImperialUnits) setButtonContent;

const OnboardingSecondPageBody({super.key, required this.setButtonContent});
final double? initialHeight;
final double? initialWeight;
final bool initialUsesImperial;

const OnboardingSecondPageBody({
super.key,
required this.setButtonContent,
this.initialHeight,
this.initialWeight,
this.initialUsesImperial = false,
});

@override
State<OnboardingSecondPageBody> createState() =>
Expand All @@ -23,6 +33,20 @@ class _OnboardingSecondPageBodyState extends State<OnboardingSecondPageBody> {

bool get _isImperialSelected => _isUnitSelected[1];

@override
void initState() {
super.initState();
if(widget.initialUsesImperial){
_parsedHeight = UnitCalc.cmToFeet(widget.initialHeight != null ? widget.initialHeight! : 0.0);
_parsedWeight = UnitCalc.kgToLbs(widget.initialWeight != null ? widget.initialWeight! : 0.0);
}else{
_parsedHeight = widget.initialHeight?.round().toDouble();
_parsedWeight = widget.initialWeight;
}
_isUnitSelected[0] = !widget.initialUsesImperial;
_isUnitSelected[1] = widget.initialUsesImperial;
}

@override
Widget build(BuildContext context) {
return SizedBox(
Expand All @@ -39,6 +63,7 @@ class _OnboardingSecondPageBodyState extends State<OnboardingSecondPageBody> {
Form(
key: _heightFormKey,
child: TextFormField(
initialValue: _isImperialSelected ? _parsedHeight?.toString() : _parsedHeight?.toString().split('.')[0],
onChanged: (text) {
if (_heightFormKey.currentState!.validate()) {
_parsedHeight = double.tryParse(text.replaceAll(',', '.'));
Expand Down Expand Up @@ -103,6 +128,7 @@ class _OnboardingSecondPageBodyState extends State<OnboardingSecondPageBody> {
Form(
key: _weightFormKey,
child: TextFormField(
initialValue: _parsedWeight?.toString(),
onChanged: (text) {
if (_weightFormKey.currentState!.validate()) {
_parsedWeight = double.tryParse(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ class OnboardingThirdPageBody extends StatefulWidget {
final Function(bool active, UserActivitySelectionEntity? selectedActivity)
setButtonContent;

const OnboardingThirdPageBody({super.key, required this.setButtonContent});
final bool initialSedentarySelected;
final bool initialLowActiveSelected;
final bool initialActiveSelected;
final bool initialVeryActiveSelected;

const OnboardingThirdPageBody({
super.key,
required this.setButtonContent,
this.initialSedentarySelected = false,
this.initialLowActiveSelected = false,
this.initialActiveSelected = false,
this.initialVeryActiveSelected = false
});

@override
State<OnboardingThirdPageBody> createState() =>
Expand All @@ -20,6 +32,15 @@ class _OnboardingThirdPageBodyState extends State<OnboardingThirdPageBody> {
bool _activeSelected = false;
bool _veryActiveSelected = false;

@override
void initState() {
super.initState();
_sedentarySelected = widget.initialSedentarySelected;
_lowActiveSelected = widget.initialLowActiveSelected;
_activeSelected = widget.initialActiveSelected;
_veryActiveSelected = widget.initialVeryActiveSelected;
}

@override
Widget build(BuildContext context) {
return SizedBox(
Expand Down