115 lines
4.1 KiB
Dart
115 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../enumerations.dart';
|
|
import '../../services/auth/auth_service.dart';
|
|
import '../../services/user_service.dart';
|
|
import '../constants.dart';
|
|
import 'profile_category_form.dart';
|
|
import 'sectors_form.dart';
|
|
|
|
class SkillsForm extends StatelessWidget {
|
|
SkillsForm({
|
|
super.key,
|
|
required this.isRegProcess,
|
|
required this.skillsSought,
|
|
required this.isEditMode,
|
|
});
|
|
|
|
final AuthService _authService = AuthService();
|
|
|
|
final bool isRegProcess;
|
|
final bool skillsSought; // flag to toggle offered and sought skills
|
|
final bool isEditMode;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder<List<SkillOption>>(
|
|
future: UserService.getSkillsFromFirebase(
|
|
skillsSought,
|
|
_authService.getCurrentUser()!.uid,
|
|
),
|
|
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',
|
|
header: skillsSought
|
|
? 'Skills you are searching for'
|
|
: 'Your own skills',
|
|
description: skillsSought
|
|
? 'Choose up to 3 areas you are looking for in a co-founder'
|
|
: 'Select up to 3 areas in which you are skilled',
|
|
saveButtonText: isRegProcess ? 'Save and continue' : 'Save',
|
|
options: SkillOption.values.toList(), // Convert enum values to list
|
|
minSelections: 1,
|
|
maxSelections: 3,
|
|
preSelectedOptions:
|
|
userSkills ?? [], // Pass pre-selected skills to the form
|
|
onSave: (selectedOptions) async {
|
|
// Handle saving selected options
|
|
bool success = await UserService.saveSkillsToFirebase(
|
|
selectedOptions.cast<SkillOption>(),
|
|
skillsSought,
|
|
_authService.getCurrentUser()!.uid,
|
|
);
|
|
|
|
// Then navigate to another screen or perform any other action
|
|
if (context.mounted) {
|
|
if (success) {
|
|
if (isRegProcess && skillsSought) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
// set following registration page HERE
|
|
builder: (context) => SectorsForm(
|
|
isRegProcess: isRegProcess,
|
|
isEditMode: false,
|
|
),
|
|
),
|
|
);
|
|
} else if (isRegProcess) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => SkillsForm(
|
|
isRegProcess: isRegProcess,
|
|
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 {
|
|
// Navigate back after saving
|
|
Navigator.pop(context);
|
|
}
|
|
}
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Failed to save user skills.'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|