Edit Skills.

master
Rafael 2024-05-31 18:31:37 +02:00
parent d246829784
commit 3aa5f2b5d3
5 changed files with 159 additions and 15 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../../enumerations.dart'; import '../../enumerations.dart';
import '../../services/auth/auth_service.dart'; import '../../services/auth/auth_service.dart';
import '../../services/user_service.dart'; import '../../services/user_service.dart';
import '../constants.dart';
import '../pages/user_vision_page.dart'; import '../pages/user_vision_page.dart';
import 'profile_category_form.dart'; import 'profile_category_form.dart';
@ -10,6 +11,7 @@ class SkillsForm extends StatelessWidget {
super.key, super.key,
required this.isRegProcess, required this.isRegProcess,
required this.skillsSought, required this.skillsSought,
required this.isEditMode,
}); });
// get instance of auth // get instance of auth
@ -17,6 +19,7 @@ class SkillsForm extends StatelessWidget {
final bool isRegProcess; final bool isRegProcess;
final bool skillsSought; // flag to toggle offered and sought skills final bool skillsSought; // flag to toggle offered and sought skills
final bool isEditMode;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -74,13 +77,25 @@ class SkillsForm extends StatelessWidget {
builder: (context) => SkillsForm( builder: (context) => SkillsForm(
isRegProcess: isRegProcess, isRegProcess: isRegProcess,
skillsSought: true, skillsSought: true,
isEditMode: false,
), ),
), ),
); );
} else {
if (isEditMode == true) {
// pass selectedOptions data back to caller
String keyToUpdate = skillsSought
? Constants.dbFieldUsersSkillsSought
: Constants.dbFieldUsersSkills;
Navigator.pop(context, {
keyToUpdate: selectedOptions,
});
} else { } else {
// Navigate back after saving // Navigate back after saving
Navigator.pop(context); Navigator.pop(context);
} }
}
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(

View File

@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cofounderella/services/user_service.dart';
import '../constants.dart'; import '../constants.dart';
import '../enumerations.dart'; import '../enumerations.dart';
@ -17,8 +18,8 @@ class UserProfile {
Gender? gender; Gender? gender;
int? born; int? born;
final String risk; final String risk;
final List<String> skills; List<SkillOption> skills;
final List<String> skillsSought; List<SkillOption> skillsSought;
List<Language> languages; List<Language> languages;
Map<String, MyLocation?> locations; Map<String, MyLocation?> locations;
@ -43,6 +44,11 @@ class UserProfile {
factory UserProfile.fromDocument(DocumentSnapshot doc) { factory UserProfile.fromDocument(DocumentSnapshot doc) {
Map<String, dynamic> data = doc.data() as Map<String, dynamic>; Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
List<SkillOption> skillsOffered = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkills]);
List<SkillOption> skillsSought = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkillsSought]);
return UserProfile( return UserProfile(
id: doc.id, id: doc.id,
uid: data[Constants.dbFieldUsersID] ?? '', uid: data[Constants.dbFieldUsersID] ?? '',
@ -50,9 +56,8 @@ class UserProfile {
name: data[Constants.dbFieldUsersName] ?? '', name: data[Constants.dbFieldUsersName] ?? '',
firstName: data[Constants.dbFieldUsersFirstName] ?? '', firstName: data[Constants.dbFieldUsersFirstName] ?? '',
lastName: data[Constants.dbFieldUsersLastName] ?? '', lastName: data[Constants.dbFieldUsersLastName] ?? '',
skills: List<String>.from(data[Constants.dbFieldUsersSkills] ?? []), skills: skillsOffered,
skillsSought: skillsSought: skillsSought,
List<String>.from(data[Constants.dbFieldUsersSkillsSought] ?? []),
risk: data[Constants.dbFieldUsersRiskTolerance] ?? '', risk: data[Constants.dbFieldUsersRiskTolerance] ?? '',
profilePictureUrl: data[Constants.dbFieldUsersProfilePic], profilePictureUrl: data[Constants.dbFieldUsersProfilePic],
bio: data[Constants.dbFieldUsersBio], bio: data[Constants.dbFieldUsersBio],

View File

@ -329,6 +329,7 @@ class _UserDataPageState extends State<UserDataPage> {
builder: (context) => SkillsForm( builder: (context) => SkillsForm(
isRegProcess: widget.isRegProcess, isRegProcess: widget.isRegProcess,
skillsSought: false, skillsSought: false,
isEditMode: false,
), ),
), ),
); );

View File

@ -1,3 +1,5 @@
import 'package:cofounderella/enumerations.dart';
import 'package:cofounderella/forms/skills_form.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
@ -80,6 +82,43 @@ class _UserProfilePageState extends State<UserProfilePage> {
} }
} }
void _editSkills({required bool skillsSought}) async {
final updatedUserData = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SkillsForm(
isRegProcess: false,
skillsSought: skillsSought,
isEditMode: true,
),
),
);
if (updatedUserData != null) {
setState(() {
// above Type of updatedUserData is dynamic, so convert
if (skillsSought) {
List<dynamic> dynamicList =
updatedUserData[Constants.dbFieldUsersSkillsSought];
myData.skillsSought =
dynamicList.map((e) => e as SkillOption).toList();
} else {
List<dynamic> dynamicList =
updatedUserData[Constants.dbFieldUsersSkills];
myData.skills = dynamicList.map((e) => e as SkillOption).toList();
}
});
}
}
void editUserSkillsInfo() async {
_editSkills(skillsSought: false);
}
void editUserSkillsSoughtInfo() async {
_editSkills(skillsSought: true);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -101,6 +140,10 @@ class _UserProfilePageState extends State<UserProfilePage> {
const SizedBox(height: 16), const SizedBox(height: 16),
Divider(color: Theme.of(context).colorScheme.primary), Divider(color: Theme.of(context).colorScheme.primary),
const SizedBox(height: 16), const SizedBox(height: 16),
_buildSkills(context),
const SizedBox(height: 16),
Divider(color: Theme.of(context).colorScheme.primary),
const SizedBox(height: 16),
], ],
), ),
), ),
@ -108,6 +151,81 @@ class _UserProfilePageState extends State<UserProfilePage> {
); );
} }
Widget _buildSkills(BuildContext context) {
return Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Skills offered',
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
),
Text(myData.skills.map((x) => x.displayName).join(', '),
style: const TextStyle(fontSize: 16)),
],
),
),
Align(
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserSkillsInfo,
),
),
],
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Skills sought',
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
),
Text(
myData.skillsSought
.map((x) => x.displayName)
.join(', '),
style: const TextStyle(fontSize: 16)),
],
),
),
Align(
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserSkillsSoughtInfo,
),
),
],
),
],
),
),
],
);
}
Widget _buildLocation(BuildContext context) { Widget _buildLocation(BuildContext context) {
int age = calcAge(myData.born); int age = calcAge(myData.born);
return Column( return Column(

View File

@ -51,6 +51,13 @@ class UserService {
skills = userData[Constants.dbFieldUsersSkills]; skills = userData[Constants.dbFieldUsersSkills];
} }
return convertSkillStringToEnum(skills);
}
return [];
}
static List<SkillOption> convertSkillStringToEnum(List<dynamic>? skills) {
if (skills != null && skills.isNotEmpty) { if (skills != null && skills.isNotEmpty) {
// Convert skills from strings to enum values // Convert skills from strings to enum values
List<SkillOption> userSkills = skills List<SkillOption> userSkills = skills
@ -59,8 +66,6 @@ class UserService {
.toList(); .toList();
return userSkills; return userSkills;
} }
}
return []; return [];
} }