diff --git a/lib/components/my_button.dart b/lib/components/my_button.dart index bbd946f..82d3d97 100644 --- a/lib/components/my_button.dart +++ b/lib/components/my_button.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; class MyButton extends StatelessWidget { - void Function()? onTap; + final void Function()? onTap; final String text; - MyButton({ + const MyButton({ super.key, required this.text, required this.onTap, diff --git a/lib/pages/user_data_page.dart b/lib/pages/user_data_page.dart index f277b11..84d5f12 100644 --- a/lib/pages/user_data_page.dart +++ b/lib/pages/user_data_page.dart @@ -59,14 +59,20 @@ class _UserDataPageState extends State { .doc(currentUserId) .get(); + if (!userSnapshot.exists || userSnapshot.data() == null) { + return; // should not happen, user entry should exist + } + + Map userFields = + userSnapshot.data() as Map; + // Extract gender and birth year - _genderFromDb = userSnapshot[Constants.dbFieldUsersGender]; - _yearFromDb = userSnapshot - .data() - .toString() - .contains(Constants.dbFieldUsersYearBorn) - ? userSnapshot[Constants.dbFieldUsersYearBorn] - : null; + if (userFields.containsKey(Constants.dbFieldUsersGender)) { + _genderFromDb = userSnapshot[Constants.dbFieldUsersGender]; + } + if (userFields.containsKey(Constants.dbFieldUsersYearBorn)) { + _yearFromDb = userSnapshot[Constants.dbFieldUsersYearBorn]; + } // Fetch locations QuerySnapshot locationSnapshot = await _firestore @@ -391,6 +397,7 @@ class _UserDataPageState extends State { : 'undefined'), const SizedBox(width: 20), DropdownMenu( + initialSelection: _selectedYear, onSelected: (int? newValue) { setState(() { _selectedYear = newValue; @@ -403,7 +410,6 @@ class _UserDataPageState extends State { ); }), label: const Text('birth year'), - initialSelection: _yearFromDb, ), ], ),