cofounderella/lib/pages/user_vision_page.dart

176 lines
5.4 KiB
Dart
Raw Normal View History

2024-05-21 14:01:44 +02:00
import "package:cloud_firestore/cloud_firestore.dart";
import "package:flutter/material.dart";
import "../constants.dart";
import "../enumerations.dart";
2024-05-21 19:37:00 +02:00
import "../forms/corporate_culture_form.dart";
2024-05-21 14:01:44 +02:00
import "../services/auth/auth_service.dart";
class MatchingForm extends StatefulWidget {
const MatchingForm({super.key, required this.isRegProcess});
final bool isRegProcess;
@override
MatchingFormState createState() => MatchingFormState();
}
class MatchingFormState extends State<MatchingForm> {
Map<VisionOption, bool> selectedVisionOptions = {
VisionOption.marketLeader: false,
VisionOption.sustainableBusiness: false,
VisionOption.innovativeProduct: false,
VisionOption.exitStrategy: false,
};
AvailabilityOption? availability;
// get instance of auth
final AuthService _authService = AuthService();
@override
void initState() {
super.initState();
_loadDataFromFirebase();
}
Future<void> _loadDataFromFirebase() async {
final userDoc = FirebaseFirestore.instance
.collection(Constants.dbCollectionUsers)
.doc(_authService.getCurrentUser()!.uid);
final snapshot = await userDoc.get();
if (snapshot.exists) {
final data = snapshot.data();
setState(() {
// Load Vision options
if (data?[Constants.dbFieldUsersVisions] != null) {
for (var option in VisionOption.values) {
selectedVisionOptions[option] = data?[Constants.dbFieldUsersVisions]
.contains(option.toString());
}
}
// Load Availability option
if (data?[Constants.dbFieldUsersAvailability] != null) {
availability = AvailabilityOption.values.firstWhere(
(e) => e.toString() == data?[Constants.dbFieldUsersAvailability],
);
}
});
}
}
Future<void> _saveDataToFirebase() async {
final userDoc = FirebaseFirestore.instance
.collection(Constants.dbCollectionUsers)
.doc(_authService.getCurrentUser()!.uid);
await userDoc.set(
{
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
);
}
bool isVisionSelected() {
return selectedVisionOptions.containsValue(true);
}
void handleSubmit() {
if (!isVisionSelected()) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
2024-05-21 19:37:00 +02:00
content: Text('Please select at least one long-term vision.'),
2024-05-21 14:01:44 +02:00
));
return;
}
if (availability == null) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Please select an availability option.'),
));
return;
}
_saveDataToFirebase();
// Handle the form submission logic here
Navigator.push(
context,
MaterialPageRoute(
2024-05-21 19:37:00 +02:00
//
// set following registration page HERE
//
builder: (context) => CultureValuesFormPage(
isRegProcess: widget.isRegProcess,
),
2024-05-21 14:01:44 +02:00
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Personal preferences'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
2024-05-21 19:37:00 +02:00
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Vision and goals',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const Text('What is your long-term vision for a startup?'),
...VisionOption.values.map((option) {
return CheckboxListTile(
title: Text(option.displayName),
value: selectedVisionOptions[option],
controlAffinity: ListTileControlAffinity.platform,
onChanged: (bool? value) {
if (value != null) {
setState(() {
selectedVisionOptions[option] = value;
});
}
},
);
}),
const SizedBox(height: 40),
const Text(
2024-05-21 14:01:44 +02:00
'Availability and commitment',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
2024-05-21 19:37:00 +02:00
const Text(
'How much time can you devote to the startup each week?',
),
...AvailabilityOption.values.map((option) {
return RadioListTile(
title: Text(option.displayName),
value: option,
groupValue: availability,
onChanged: (AvailabilityOption? value) {
setState(() {
availability = value;
});
},
);
}),
const SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: handleSubmit,
child:
Text(widget.isRegProcess ? 'Save and continue' : 'Save'),
),
2024-05-21 14:01:44 +02:00
),
2024-05-21 19:37:00 +02:00
],
),
2024-05-21 14:01:44 +02:00
),
),
);
}
}