some code refactoring

master
Rafael 2024-06-10 17:38:47 +02:00
parent 8120ebda3d
commit a6d5d1107a
4 changed files with 39 additions and 74 deletions

View File

@ -13,6 +13,7 @@ import '../models/language.dart';
import '../models/language_setting.dart'; import '../models/language_setting.dart';
import '../models/location.dart'; import '../models/location.dart';
import '../services/auth/auth_service.dart'; import '../services/auth/auth_service.dart';
import '../utils/helper.dart';
import '../utils/math.dart'; import '../utils/math.dart';
class UserDataPage extends StatefulWidget { class UserDataPage extends StatefulWidget {
@ -590,17 +591,6 @@ class _UserDataPageState extends State<UserDataPage> {
); );
void _showSnackBar(String message) { void _showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar( showErrorSnackBar(context, message);
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
action: SnackBarAction(
label: 'Dismiss',
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
),
);
} }
} }

View File

@ -276,14 +276,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
if (isOwner) if (isOwner)
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0), padding: const EdgeInsets.only(left: 8.0),
child: Align( child: _editButton(context, editUserCommunicationInfo),
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserCommunicationInfo,
),
),
), ),
], ],
), ),
@ -344,14 +337,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
if (isOwner) if (isOwner)
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0), padding: const EdgeInsets.only(left: 8.0),
child: Align( child: _editButton(context, editUserWorkCultureInfo),
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserWorkCultureInfo,
),
),
), ),
], ],
), ),
@ -412,15 +398,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
], ],
), ),
), ),
if (isOwner) if (isOwner) _editButton(context, editUserVisionInfo),
Align(
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserVisionInfo,
),
),
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@ -480,15 +458,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
], ],
), ),
), ),
if (isOwner) if (isOwner) _editButton(context, editUserSkillsInfo),
Align(
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserSkillsInfo,
),
),
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@ -513,15 +483,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
], ],
), ),
), ),
if (isOwner) if (isOwner) _editButton(context, editUserSkillsSoughtInfo),
Align(
alignment: Alignment.topRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserSkillsSoughtInfo,
),
),
], ],
), ),
], ],
@ -560,14 +522,8 @@ class _UserProfilePageState extends State<UserProfilePage> {
style: const TextStyle(fontSize: 16)), style: const TextStyle(fontSize: 16)),
], ],
), ),
Align( _editButton(context, editUserDataInfo,
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight),
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editUserDataInfo,
),
),
], ],
), ),
if (isOwner) const SizedBox(height: 16), if (isOwner) const SizedBox(height: 16),
@ -632,14 +588,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
return Column( return Column(
children: [ children: [
if (isOwner) if (isOwner)
Align( _editButton(context, editNameInfo, alignment: Alignment.bottomRight),
alignment: Alignment.bottomRight,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: editNameInfo,
),
),
CircleAvatar( CircleAvatar(
radius: 80, radius: 80,
backgroundImage: backgroundImage:
@ -683,4 +632,16 @@ class _UserProfilePageState extends State<UserProfilePage> {
], ],
); );
} }
Widget _editButton(BuildContext context, void Function()? onPressedFunction,
{Alignment alignment = Alignment.topRight}) {
return Align(
alignment: alignment,
child: OutlinedButton.icon(
label: const Text('Edit'),
icon: const Icon(Icons.edit),
onPressed: onPressedFunction,
),
);
}
} }

View File

@ -5,6 +5,7 @@ import '../constants.dart';
import '../enumerations.dart'; import '../enumerations.dart';
import '../forms/corporate_culture_form.dart'; import '../forms/corporate_culture_form.dart';
import '../services/auth/auth_service.dart'; import '../services/auth/auth_service.dart';
import '../utils/helper.dart';
class UserVisionPage extends StatefulWidget { class UserVisionPage extends StatefulWidget {
const UserVisionPage( const UserVisionPage(
@ -87,9 +88,7 @@ class UserVisionPageState extends State<UserVisionPage> {
} }
void _showSnackBar(String message) { void _showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar( showErrorSnackBar(context, message);
SnackBar(content: Text(message)),
);
} }
bool isVisionSelected() { bool isVisionSelected() {

View File

@ -96,3 +96,18 @@ void showMsg(BuildContext context, String title, String content) {
), ),
); );
} }
void showErrorSnackBar(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
action: SnackBarAction(
label: 'Dismiss',
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
),
);
}