diff --git a/lib/forms/corporate_culture_form.dart b/lib/forms/corporate_culture_form.dart index 762096d..aa36ba1 100644 --- a/lib/forms/corporate_culture_form.dart +++ b/lib/forms/corporate_culture_form.dart @@ -123,6 +123,8 @@ class CultureValuesFormPageState extends State { MaterialPageRoute( // // set following registration page HERE + // this Page (CorporateCultureForm) is optional as of 22.06.24 + // and therefore not called anymore during RegProcess // builder: (context) => RisksFormPage( isRegProcess: widget.isRegProcess, diff --git a/lib/forms/risks_form.dart b/lib/forms/risks_form.dart index d9d71f2..a680ea2 100644 --- a/lib/forms/risks_form.dart +++ b/lib/forms/risks_form.dart @@ -2,6 +2,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import '../components/my_elevated_button.dart'; +import '../components/text_bold.dart'; import '../constants.dart'; import '../enumerations.dart'; import '../pages/registration_complete_page.dart'; @@ -20,7 +21,7 @@ class RisksFormPage extends StatefulWidget { } class RisksFormPageState extends State { - CommunicationPreference? communicationPreference; + AvailabilityOption? availability; RiskTolerance? riskPreference; final AuthService _authService = AuthService(); @@ -41,11 +42,11 @@ class RisksFormPageState extends State { final data = snapshot.data(); setState(() { if (data != null) { - // Load Communication Preference - if (data[Constants.dbFieldUsersCommunication] != null) { - communicationPreference = CommunicationPreference.values - .firstWhereOrNull((x) => - x.toString() == data[Constants.dbFieldUsersCommunication]); + // Load Availability option + if (data[Constants.dbFieldUsersAvailability] != null) { + availability = AvailabilityOption.values.firstWhereOrNull( + (x) => x.toString() == data[Constants.dbFieldUsersAvailability], + ); } // Load Risk Tolerance if (data[Constants.dbFieldUsersRiskTolerance] != null) { @@ -65,8 +66,7 @@ class RisksFormPageState extends State { await userDoc.set( { - Constants.dbFieldUsersCommunication: - communicationPreference?.toString(), + Constants.dbFieldUsersAvailability: availability.toString(), Constants.dbFieldUsersRiskTolerance: riskPreference?.toString(), }, SetOptions(merge: true), // avoid overwriting existing data @@ -83,13 +83,12 @@ class RisksFormPageState extends State { } Future handleSubmit() async { - if (communicationPreference == null) { - showErrorSnackBar(context, 'Please select a communication preference.'); + if (availability == null) { + _showSnackBar('Please select an availability option.'); return; } if (riskPreference == null) { - showErrorSnackBar( - context, 'Please select the willingness to take risks.'); + showErrorSnackBar(context, 'Please select a willingness to take risks.'); return; } // Handle the form submission logic here @@ -116,7 +115,7 @@ class RisksFormPageState extends State { if (widget.isEditMode == true) { // pass selectedOptions data back to caller Navigator.pop(context, { - Constants.dbFieldUsersCommunication: communicationPreference, + Constants.dbFieldUsersAvailability: availability, Constants.dbFieldUsersRiskTolerance: riskPreference, }); } else { @@ -144,28 +143,24 @@ class RisksFormPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + const TextBold(text: 'Availability and commitment'), const Text( - 'Communication preference', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + 'How much time can you devote to the startup each week?', ), - const Text('How do you prefer to communicate in a team?'), - ...CommunicationPreference.values.map((option) { + ...AvailabilityOption.values.map((option) { return RadioListTile( title: Text(option.displayName), value: option, - groupValue: communicationPreference, - onChanged: (CommunicationPreference? value) { + groupValue: availability, + onChanged: (AvailabilityOption? value) { setState(() { - communicationPreference = value; + availability = value; }); }, ); }), const SizedBox(height: 40), - const Text( - 'Risk tolerance', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), - ), + const TextBold(text: 'Risk tolerance'), const Text('How do you deal with uncertainty and risk?'), ...RiskTolerance.values.map((option) { return RadioListTile( diff --git a/lib/forms/sectors_form.dart b/lib/forms/sectors_form.dart index 26cde63..3d03355 100644 --- a/lib/forms/sectors_form.dart +++ b/lib/forms/sectors_form.dart @@ -3,8 +3,8 @@ import '../../enumerations.dart'; import '../../services/auth/auth_service.dart'; import '../../services/user_service.dart'; import '../constants.dart'; -import '../pages/user_vision_page.dart'; import 'profile_category_form.dart'; +import 'risks_form.dart'; class SectorsForm extends StatelessWidget { SectorsForm({ @@ -54,7 +54,7 @@ class SectorsForm extends StatelessWidget { context, MaterialPageRoute( // set following registration page HERE - builder: (context) => UserVisionPage( + builder: (context) => RisksFormPage( isRegProcess: isRegProcess, isEditMode: false, ), diff --git a/lib/pages/user_profile_page.dart b/lib/pages/user_profile_page.dart index bfae40f..e55f4f2 100644 --- a/lib/pages/user_profile_page.dart +++ b/lib/pages/user_profile_page.dart @@ -201,7 +201,7 @@ class _UserProfilePageState extends State { } } - void editUserCommunicationInfo() async { + void editUserRiskInfo() async { final updatedUserData = await Navigator.push( context, MaterialPageRoute( @@ -255,12 +255,12 @@ class _UserProfilePageState extends State { if (isOwner) Divider(color: Theme.of(context).colorScheme.primary), if (isOwner) const SizedBox(height: 16), - _buildVision(context), + _buildRisks(context), const SizedBox(height: 16), if (isOwner) Divider(color: Theme.of(context).colorScheme.primary), if (isOwner) const SizedBox(height: 16), - _buildRisks(context), + _buildVision(context), const SizedBox(height: 16), if (isOwner) Divider(color: Theme.of(context).colorScheme.primary), @@ -295,7 +295,7 @@ class _UserProfilePageState extends State { CircleAvatar( radius: 80, backgroundImage: - ((profileImageUrl != null && profileImageUrl!.isNotEmpty)) + (profileImageUrl != null && profileImageUrl!.isNotEmpty) ? NetworkImage(profileImageUrl!) : null, child: (profileImageUrl == null || profileImageUrl!.isEmpty) @@ -535,7 +535,7 @@ class _UserProfilePageState extends State { ); } - Widget _buildVision(BuildContext context) { + Widget _buildRisks(BuildContext context) { return Column( children: [ Align( @@ -561,7 +561,7 @@ class _UserProfilePageState extends State { ], ), ), - if (isOwner) _editButton(context, editUserVisionInfo), + if (isOwner) _editButton(context, editUserRiskInfo), ], ), const SizedBox(height: 16), @@ -573,15 +573,12 @@ class _UserProfilePageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - 'Vision and Goals', + 'Risk profile', style: TextStyle( color: Theme.of(context).colorScheme.primary, ), ), - Text( - myData.visions - .map((x) => x.displayName) - .join(',\n'), + Text(myData.risk.displayName, style: const TextStyle(fontSize: 16)), ], ), @@ -595,7 +592,7 @@ class _UserProfilePageState extends State { ); } - Widget _buildRisks(BuildContext context) { + Widget _buildVision(BuildContext context) { return Column( children: [ Align( @@ -624,7 +621,7 @@ class _UserProfilePageState extends State { if (isOwner) Padding( padding: const EdgeInsets.only(left: 8.0), - child: _editButton(context, editUserCommunicationInfo), + child: _editButton(context, editUserVisionInfo), ), ], ), @@ -637,12 +634,15 @@ class _UserProfilePageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - 'Risk profile', + 'Vision and Goals', style: TextStyle( color: Theme.of(context).colorScheme.primary, ), ), - Text(myData.risk.displayName, + Text( + myData.visions + .map((x) => x.displayName) + .join(',\n'), style: const TextStyle(fontSize: 16)), ], ), diff --git a/lib/pages/user_vision_page.dart b/lib/pages/user_vision_page.dart index c7f1eeb..d560962 100644 --- a/lib/pages/user_vision_page.dart +++ b/lib/pages/user_vision_page.dart @@ -5,7 +5,7 @@ import '../components/my_elevated_button.dart'; import '../components/text_bold.dart'; import '../constants.dart'; import '../enumerations.dart'; -import '../forms/corporate_culture_form.dart'; +import '../forms/risks_form.dart'; import '../services/auth/auth_service.dart'; import '../utils/helper_dialogs.dart'; @@ -27,7 +27,7 @@ class UserVisionPageState extends State { VisionOption.innovativeProduct: false, VisionOption.exitStrategy: false, }; - AvailabilityOption? availability; + CommunicationPreference? communicationPreference; final AuthService _authService = AuthService(); @@ -45,24 +45,24 @@ class UserVisionPageState extends State { if (snapshot.exists) { final data = snapshot.data(); - setState( - () { + setState(() { + if (data != null) { + // Load Communication Preference + if (data[Constants.dbFieldUsersCommunication] != null) { + communicationPreference = CommunicationPreference.values + .firstWhereOrNull((x) => + x.toString() == data[Constants.dbFieldUsersCommunication]); + } // Load Vision options - if (data?[Constants.dbFieldUsersVisions] != null) { + if (data[Constants.dbFieldUsersVisions] != null) { for (var option in VisionOption.values) { selectedVisionOptions[option] = - data?[Constants.dbFieldUsersVisions] + data[Constants.dbFieldUsersVisions] .contains(option.toString()); } } - // Load Availability option - if (data?[Constants.dbFieldUsersAvailability] != null) { - availability = AvailabilityOption.values.firstWhereOrNull( - (e) => e.toString() == data?[Constants.dbFieldUsersAvailability], - ); - } - }, - ); + } + }); } } @@ -74,11 +74,12 @@ class UserVisionPageState extends State { await userDoc.set( { + Constants.dbFieldUsersCommunication: + communicationPreference?.toString(), Constants.dbFieldUsersVisions: selectedVisionOptions.entries .where((entry) => entry.value) .map((entry) => entry.key.toString()) .toList(), - Constants.dbFieldUsersAvailability: availability?.toString(), }, SetOptions(merge: true), // avoid overwriting existing data ); @@ -98,14 +99,15 @@ class UserVisionPageState extends State { } Future handleSubmit() async { + if (communicationPreference == null) { + showErrorSnackBar(context, 'Please select a communication preference.'); + return; + } if (!isVisionSelected()) { _showSnackBar('Please select at least one long-term vision.'); return; } - if (availability == null) { - _showSnackBar('Please select an availability option.'); - return; - } + // Handle the form submission logic here bool success = await _saveDataToFirebase(); if (success) { @@ -122,8 +124,11 @@ class UserVisionPageState extends State { MaterialPageRoute( // // set following registration page HERE + // this Page (UserVisionPage) is optional as of 22.06.24 + // and therefore not called anymore during RegProcess // - builder: (context) => CultureValuesFormPage( + // + builder: (context) => RisksFormPage( isRegProcess: widget.isRegProcess, isEditMode: false, ), @@ -133,11 +138,11 @@ class UserVisionPageState extends State { if (widget.isEditMode == true) { // pass selectedOptions data back to caller Navigator.pop(context, { + Constants.dbFieldUsersCommunication: communicationPreference, Constants.dbFieldUsersVisions: selectedVisionOptions.entries .where((entry) => entry.value) .map((entry) => entry.key) .toList(), - Constants.dbFieldUsersAvailability: availability, }); } else { Navigator.pop(context); @@ -164,18 +169,16 @@ class UserVisionPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const TextBold(text: 'Availability and commitment'), - const Text( - 'How much time can you devote to the startup each week?', - ), - ...AvailabilityOption.values.map((option) { + const TextBold(text: 'Communication preference'), + const Text('How do you prefer to communicate in a team?'), + ...CommunicationPreference.values.map((option) { return RadioListTile( title: Text(option.displayName), value: option, - groupValue: availability, - onChanged: (AvailabilityOption? value) { + groupValue: communicationPreference, + onChanged: (CommunicationPreference? value) { setState(() { - availability = value; + communicationPreference = value; }); }, ); diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index b35928d..30fa462 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -59,15 +59,22 @@ class UserService { } static List convertSkillStringToEnum(List? skills) { + List userSkills = []; if (skills != null && skills.isNotEmpty) { // Convert skills from strings to enum values - List userSkills = skills - .map((skill) => SkillOption.values - .firstWhere((x) => x.toString() == 'SkillOption.$skill')) - .toList(); - return userSkills; + for (var skill in skills) { + try { + SkillOption skillOption = SkillOption.values.firstWhere( + (x) => x.toString() == 'SkillOption.$skill', + ); + userSkills.add(skillOption); + } catch (e) { + // Ignore invalid values + continue; + } + } } - return []; + return userSkills; } static List convertSectorStringToEnum(List? sectors) {