Revised UserDataPage

master
Rafael 2024-06-16 01:50:37 +02:00
parent 86bacaa9f5
commit a2a7ae5fc6
1 changed files with 76 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import '../components/location_dialog.dart'; import '../components/location_dialog.dart';
import '../components/my_button.dart'; import '../components/my_button.dart';
import '../components/text_with_bold.dart';
import '../constants.dart'; import '../constants.dart';
import '../enumerations.dart'; import '../enumerations.dart';
import '../forms/skills_form.dart'; import '../forms/skills_form.dart';
@ -206,6 +207,9 @@ class _UserDataPageState extends State<UserDataPage> {
await locationsRef await locationsRef
.doc(Constants.dbDocMainLocation) .doc(Constants.dbDocMainLocation)
.set(_mainLocation!.toMap()); .set(_mainLocation!.toMap());
} else {
_showSnackBar('No location selected');
return false;
} }
} }
@ -375,6 +379,13 @@ class _UserDataPageState extends State<UserDataPage> {
AuthService().signOut(); AuthService().signOut();
}, },
icon: const Icon(Icons.logout), icon: const Icon(Icons.logout),
),
if (widget.isEditMode && !widget.isRegProcess)
IconButton(
onPressed: () {
_saveButtonClicked(context);
},
icon: const Icon(Icons.save),
) )
], ],
), ),
@ -410,15 +421,23 @@ class _UserDataPageState extends State<UserDataPage> {
const SizedBox(height: 10), const SizedBox(height: 10),
], ],
// Button to set main location // Button to set main location
Center( Row(
child: ElevatedButton( mainAxisAlignment: MainAxisAlignment.start,
onPressed: () { children: [
_showLocationDialog(true); Center(
}, child: ElevatedButton.icon(
child: Text(_mainLocation != null icon: _mainLocation != null
? 'Change Main Location' ? const Icon(Icons.edit_location_alt_outlined)
: 'Set Main Location'), : const Icon(Icons.location_on_outlined),
), label: Text(_mainLocation != null
? 'Edit Main Location'
: 'Set Main Location'),
onPressed: () {
_showLocationDialog(true);
},
),
),
],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
// Display selected secondary location // Display selected secondary location
@ -430,29 +449,39 @@ class _UserDataPageState extends State<UserDataPage> {
Text(_secondaryLocation!.toString()), Text(_secondaryLocation!.toString()),
const SizedBox(height: 10), const SizedBox(height: 10),
], ],
if (_mainLocation != null) ...[ Row(
// Button to set secondary location mainAxisAlignment: MainAxisAlignment.start,
Center( children: [
child: ElevatedButton( if (_mainLocation != null) ...[
onPressed: () { // Button to set secondary location
_showLocationDialog(false); Center(
}, child: ElevatedButton.icon(
child: Text(_secondaryLocation != null icon: _secondaryLocation != null
? 'Change Secondary Location' ? const Icon(Icons.edit_location_alt_outlined)
: 'Add Secondary Location'), : const Icon(Icons.add_location),
), onPressed: () {
), _showLocationDialog(false);
], },
// Display selected secondary location or remove button label: Text(_secondaryLocation != null
if (_secondaryLocation != null) ...[ ? 'Edit'
const SizedBox(height: 12), : 'Add location'),
Center( ),
child: ElevatedButton( ),
onPressed: _removeSecondaryLocation, ],
child: const Text('Remove Secondary Location'), const SizedBox(width: 10),
), // Display selected secondary location or remove button
), if (_secondaryLocation != null) ...[
], const SizedBox(height: 12),
Center(
child: ElevatedButton.icon(
onPressed: _removeSecondaryLocation,
label: const Text('Remove'),
icon: const Icon(Icons.wrong_location_outlined),
),
),
],
],
),
const SizedBox(height: 20), const SizedBox(height: 20),
const Text( const Text(
'Age', 'Age',
@ -463,7 +492,7 @@ class _UserDataPageState extends State<UserDataPage> {
const Padding(padding: EdgeInsets.symmetric(horizontal: 8)), const Padding(padding: EdgeInsets.symmetric(horizontal: 8)),
Text(_selectedYear != null Text(_selectedYear != null
? '${calcAge(_selectedYear)} years old' ? '${calcAge(_selectedYear)} years old'
: 'undefined age'), : 'not specified'),
const SizedBox(width: 20), const SizedBox(width: 20),
DropdownMenu( DropdownMenu(
initialSelection: _selectedYear, initialSelection: _selectedYear,
@ -483,12 +512,15 @@ class _UserDataPageState extends State<UserDataPage> {
], ],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
Text( const Text(
'Gender (${genderView.name} selected)', 'Gender',
style: style: TextStyle(
const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), fontSize: 18,
fontWeight: FontWeight.bold,
),
), ),
Center( Align(
alignment: Alignment.centerLeft,
child: SegmentedButton<Gender>( child: SegmentedButton<Gender>(
style: SegmentedButton.styleFrom( style: SegmentedButton.styleFrom(
selectedBackgroundColor: Colors.blue, selectedBackgroundColor: Colors.blue,
@ -523,7 +555,7 @@ class _UserDataPageState extends State<UserDataPage> {
style: style:
const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
), ),
...languagesList.map(buildSingleCheckbox), // ... spread operator ...languagesList.map(buildSingleCheckbox),
const Divider(), const Divider(),
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@ -564,7 +596,8 @@ class _UserDataPageState extends State<UserDataPage> {
required VoidCallback onClicked, required VoidCallback onClicked,
}) => }) =>
ListTile( ListTile(
tileColor: Theme.of(context).colorScheme.secondary, selected: languageSetting.isSelected,
selectedColor: Colors.blue,
onTap: onClicked, onTap: onClicked,
leading: SizedBox( leading: SizedBox(
width: 48, width: 48,
@ -573,11 +606,10 @@ class _UserDataPageState extends State<UserDataPage> {
languageSetting.language.iconFile, languageSetting.language.iconFile,
), ),
), ),
title: Text( title: TextWithBold(
languageSetting.language.nativeName, boldText: languageSetting.language.nativeName,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), trailingText: ' / ${languageSetting.language.name}',
), ),
subtitle: Text(languageSetting.language.name),
trailing: Checkbox( trailing: Checkbox(
value: languageSetting.isSelected, value: languageSetting.isSelected,
onChanged: (value) => onClicked(), onChanged: (value) => onClicked(),