cofounderella/lib/forms/skills_form.dart

98 lines
3.5 KiB
Dart

import 'package:cofounderella/pages/user_vision_page.dart';
import 'package:flutter/material.dart';
import '../../enumerations.dart';
import '../../services/auth/auth_service.dart';
import '../../services/user_service.dart';
import 'profile_category_form.dart';
class SkillsForm extends StatelessWidget {
SkillsForm({
super.key,
required this.isRegProcess,
required this.skillsSought,
});
// get instance of auth
final AuthService _authService = AuthService();
final bool isRegProcess;
final bool skillsSought; // flag to toggle offered and sought skills
@override
Widget build(BuildContext context) {
return FutureBuilder<List<SkillOption>>(
future: UserService().getSkillsFromFirebase(
skillsSought,
_authService.getCurrentUser()!.uid,
), // Fetch skills from Firebase
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) => MatchingForm(isRegProcess: isRegProcess),
),
);
} else if (isRegProcess) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SkillsForm(
isRegProcess: isRegProcess,
skillsSought: true,
),
),
);
} else {
// Navigate back after saving
Navigator.pop(context);
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to save user skills.'),
),
);
}
}
},
);
}
},
);
}
}