Fix: Loading data

master
Rafael 2024-05-16 16:57:17 +02:00
parent 13a1651af7
commit bf20cbbd1f
2 changed files with 16 additions and 10 deletions

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MyButton extends StatelessWidget { class MyButton extends StatelessWidget {
void Function()? onTap; final void Function()? onTap;
final String text; final String text;
MyButton({ const MyButton({
super.key, super.key,
required this.text, required this.text,
required this.onTap, required this.onTap,

View File

@ -59,14 +59,20 @@ class _UserDataPageState extends State<UserDataPage> {
.doc(currentUserId) .doc(currentUserId)
.get(); .get();
if (!userSnapshot.exists || userSnapshot.data() == null) {
return; // should not happen, user entry should exist
}
Map<String, dynamic> userFields =
userSnapshot.data() as Map<String, dynamic>;
// Extract gender and birth year // Extract gender and birth year
if (userFields.containsKey(Constants.dbFieldUsersGender)) {
_genderFromDb = userSnapshot[Constants.dbFieldUsersGender]; _genderFromDb = userSnapshot[Constants.dbFieldUsersGender];
_yearFromDb = userSnapshot }
.data() if (userFields.containsKey(Constants.dbFieldUsersYearBorn)) {
.toString() _yearFromDb = userSnapshot[Constants.dbFieldUsersYearBorn];
.contains(Constants.dbFieldUsersYearBorn) }
? userSnapshot[Constants.dbFieldUsersYearBorn]
: null;
// Fetch locations // Fetch locations
QuerySnapshot locationSnapshot = await _firestore QuerySnapshot locationSnapshot = await _firestore
@ -391,6 +397,7 @@ class _UserDataPageState extends State<UserDataPage> {
: 'undefined'), : 'undefined'),
const SizedBox(width: 20), const SizedBox(width: 20),
DropdownMenu( DropdownMenu(
initialSelection: _selectedYear,
onSelected: (int? newValue) { onSelected: (int? newValue) {
setState(() { setState(() {
_selectedYear = newValue; _selectedYear = newValue;
@ -403,7 +410,6 @@ class _UserDataPageState extends State<UserDataPage> {
); );
}), }),
label: const Text('birth year'), label: const Text('birth year'),
initialSelection: _yearFromDb,
), ),
], ],
), ),