2024-05-15 13:35:01 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../enumerations.dart';
|
|
|
|
import '../../services/auth/auth_service.dart';
|
2024-05-20 01:16:54 +02:00
|
|
|
import '../../services/user_service.dart';
|
2024-05-31 18:31:37 +02:00
|
|
|
import '../constants.dart';
|
2024-05-30 01:10:53 +02:00
|
|
|
import '../pages/user_vision_page.dart';
|
2024-05-15 13:35:01 +02:00
|
|
|
import 'profile_category_form.dart';
|
|
|
|
|
|
|
|
class SkillsForm extends StatelessWidget {
|
2024-05-17 23:08:26 +02:00
|
|
|
SkillsForm({
|
|
|
|
super.key,
|
|
|
|
required this.isRegProcess,
|
|
|
|
required this.skillsSought,
|
2024-05-31 18:31:37 +02:00
|
|
|
required this.isEditMode,
|
2024-05-17 23:08:26 +02:00
|
|
|
});
|
2024-05-15 13:35:01 +02:00
|
|
|
|
2024-05-20 01:16:54 +02:00
|
|
|
// get instance of auth
|
2024-05-15 13:35:01 +02:00
|
|
|
final AuthService _authService = AuthService();
|
|
|
|
|
2024-05-17 23:08:26 +02:00
|
|
|
final bool isRegProcess;
|
2024-05-15 13:35:01 +02:00
|
|
|
final bool skillsSought; // flag to toggle offered and sought skills
|
2024-05-31 18:31:37 +02:00
|
|
|
final bool isEditMode;
|
2024-05-15 13:35:01 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder<List<SkillOption>>(
|
2024-05-30 01:10:53 +02:00
|
|
|
future: UserService.getSkillsFromFirebase(
|
2024-05-20 01:16:54 +02:00
|
|
|
skillsSought,
|
|
|
|
_authService.getCurrentUser()!.uid,
|
|
|
|
), // Fetch skills from Firebase
|
2024-05-15 13:35:01 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
|
|
// Show loading indicator while fetching data
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
return Text('Error: ${snapshot.error}');
|
|
|
|
} else {
|
|
|
|
List<SkillOption>? userSkills = snapshot.data;
|
|
|
|
return ProfileCategoryForm(
|
|
|
|
title: 'Skills',
|
2024-05-20 01:16:54 +02:00
|
|
|
header: skillsSought
|
|
|
|
? 'Skills you are searching for'
|
|
|
|
: 'Your own skills',
|
2024-05-15 13:35:01 +02:00
|
|
|
description: skillsSought
|
2024-05-17 23:08:26 +02:00
|
|
|
? 'Choose up to 3 areas you are looking for in a co-founder'
|
2024-05-15 13:35:01 +02:00
|
|
|
: 'Select up to 3 areas in which you are skilled',
|
2024-05-17 23:08:26 +02:00
|
|
|
saveButtonText: isRegProcess ? 'Save and continue' : 'Save',
|
2024-05-15 13:35:01 +02:00
|
|
|
options: SkillOption.values.toList(), // Convert enum values to list
|
|
|
|
minSelections: 1,
|
|
|
|
maxSelections: 3,
|
|
|
|
preSelectedOptions:
|
|
|
|
userSkills ?? [], // Pass pre-selected skills to the form
|
2024-05-17 23:08:26 +02:00
|
|
|
onSave: (selectedOptions) async {
|
2024-05-15 13:35:01 +02:00
|
|
|
// Handle saving selected options
|
2024-05-30 01:10:53 +02:00
|
|
|
bool success = await UserService.saveSkillsToFirebase(
|
2024-05-20 01:16:54 +02:00
|
|
|
selectedOptions.cast<SkillOption>(),
|
|
|
|
skillsSought,
|
|
|
|
_authService.getCurrentUser()!.uid,
|
|
|
|
);
|
2024-05-17 23:08:26 +02:00
|
|
|
|
2024-05-15 13:35:01 +02:00
|
|
|
// Then navigate to another screen or perform any other action???
|
2024-05-17 23:08:26 +02:00
|
|
|
if (context.mounted) {
|
|
|
|
if (success) {
|
2024-05-20 01:16:54 +02:00
|
|
|
if (isRegProcess && skillsSought) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2024-05-21 14:01:44 +02:00
|
|
|
// set following registration page HERE
|
2024-05-30 01:10:53 +02:00
|
|
|
builder: (context) =>
|
2024-05-31 03:20:42 +02:00
|
|
|
UserVisionPage(isRegProcess: isRegProcess),
|
2024-05-17 23:08:26 +02:00
|
|
|
),
|
2024-05-20 01:16:54 +02:00
|
|
|
);
|
|
|
|
} else if (isRegProcess) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => SkillsForm(
|
|
|
|
isRegProcess: isRegProcess,
|
|
|
|
skillsSought: true,
|
2024-05-31 18:31:37 +02:00
|
|
|
isEditMode: false,
|
2024-05-20 01:16:54 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
2024-05-31 18:31:37 +02:00
|
|
|
if (isEditMode == true) {
|
|
|
|
// pass selectedOptions data back to caller
|
|
|
|
String keyToUpdate = skillsSought
|
|
|
|
? Constants.dbFieldUsersSkillsSought
|
|
|
|
: Constants.dbFieldUsersSkills;
|
|
|
|
|
|
|
|
Navigator.pop(context, {
|
|
|
|
keyToUpdate: selectedOptions,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Navigate back after saving
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
2024-05-20 01:16:54 +02:00
|
|
|
}
|
2024-05-17 23:08:26 +02:00
|
|
|
} else {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
const SnackBar(
|
|
|
|
content: Text('Failed to save user skills.'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-05-15 13:35:01 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|