Google authentikáció bevezetése

This commit is contained in:
2026-07-06 09:53:33 +02:00
parent 2bd39fbd4e
commit c01fdcf012
8 changed files with 500 additions and 51 deletions
+81 -41
View File
@@ -4,6 +4,7 @@ import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:terepi_seged/pages/ntrip_settings/presentation/views/ntrip_settings_sheet.dart';
import 'package:terepi_seged/routes/app_pages.dart';
import 'package:terepi_seged/services/auth_service.dart';
import 'package:terepi_seged/services/ntrip_service.dart';
import 'package:terepi_seged/services/project_service.dart';
@@ -160,6 +161,18 @@ class AppDrawer extends StatelessWidget {
// _showBasemapPicker(context);
},
),
// ListTile(
// leading: const Icon(Icons.man_3),
// title: const Text('Bejelentkezés'),
// onTap: () async {
// Get.back();
// // _showBasemapPicker(context);
// final crtl1 = Get.find<AuthController>();
// if (crtl1 != null) {
// await crtl1.signIn();
// }
// },
// ),
ListTile(
leading: const Icon(Icons.straighten),
@@ -234,49 +247,76 @@ class _DrawerHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: Obx(() { final user = AuthService.to.currentUser.value; ... })
// amikor az AuthService be lesz kötve.
return Container(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
child: Row(children: [
CircleAvatar(
radius: 22,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Text(
'?', // user?.fullName[0].toUpperCase() ?? '?'
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onPrimaryContainer,
return Obx(() {
final auth = AuthService.to;
final signedIn = auth.isSignedIn;
return InkWell(
// Kijelentkezve: koppintás = Google-bejelentkezés indítása.
onTap: signedIn || auth.isBusy.value ? null : _signIn,
child: Container(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
child: Row(children: [
CircleAvatar(
radius: 22,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
backgroundImage:
auth.avatarUrl != null ? NetworkImage(auth.avatarUrl!) : null,
child: auth.avatarUrl == null
? Text(
signedIn ? auth.displayName[0].toUpperCase() : '?',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
)
: null,
),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Ismeretlen felhasználó',
// user?.fullName ?? 'Ismeretlen felhasználó'
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
),
overflow: TextOverflow.ellipsis,
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
signedIn ? auth.displayName : 'Nincs bejelentkezve',
style: const TextStyle(
fontWeight: FontWeight.w600, fontSize: 14),
overflow: TextOverflow.ellipsis,
),
Text(
signedIn
? auth.email
: 'Koppints a Google-bejelentkezéshez',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.secondary,
),
overflow: TextOverflow.ellipsis,
),
],
),
Text(
'Vendég', // user?.role.label ?? ''
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.secondary,
),
),
],
),
),
if (!signedIn)
auth.isBusy.value
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2))
: const Icon(Icons.login, size: 18),
]),
),
]),
);
);
});
}
Future<void> _signIn() async {
try {
await AuthService.to.signInWithGoogle();
} catch (e) {
Get.snackbar('Bejelentkezés', e.toString(),
snackPosition: SnackPosition.BOTTOM);
}
}
}
@@ -332,7 +372,7 @@ class _DrawerFooter extends StatelessWidget {
FilledButton(
onPressed: () {
Get.back();
// AuthService.to.signOut();
AuthService.to.signOut();
},
child: const Text('Kilépés'),
),