2025-05-14 18:06:20 +02:00

99 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import '../services/googleAuthService.dart';
class ProfilePage extends StatefulWidget {
const ProfilePage({super.key});
@override
State<ProfilePage> createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
String? userName;
String? profilePictureUrl;
@override
void initState() {
super.initState();
_loadUser();
}
void _loadUser() {
final user = GoogleAuthService.currentUser;
if (user != null) {
setState(() {
userName = user.name;
});
//Hämtar profilbild direkt från google
final account = GoogleAuthService.getCurrentGoogleAccount();
if (account != null) {
setState(() {
profilePictureUrl = account.photoUrl;
});
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF212121),
appBar: AppBar(
backgroundColor: const Color(0xFF212121),
elevation: 0,
iconTheme: const IconThemeData(color: Colors.white),
title: const Text(
'Profil',
style: TextStyle(color: Colors.white),
),
actions: [
IconButton(
icon: const Icon(Icons.logout, color: Colors.white),
onPressed: () async {
await GoogleAuthService.logout(context);
},
),
],
),
body: SafeArea(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(
radius: 50,
backgroundImage: profilePictureUrl != null
? NetworkImage(profilePictureUrl!)
: null,
backgroundColor: Colors.grey[700],
child: profilePictureUrl == null
? const Icon(Icons.person, size: 50, color: Colors.grey)
: null,
),
const SizedBox(height: 20),
Text(
userName ?? 'Användarnamn saknas',
style: const TextStyle(fontSize: 24, color: Colors.white),
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(10),
height: 150,
width: MediaQuery.of(context).size.width * 0.8,
color: Colors.grey[800],
child: const Center(
child: Text(
'Laginformation kommer här',
style: TextStyle(color: Colors.white70),
),
),
),
],
),
),
),
);
}
}