181 lines
7.4 KiB
Dart
181 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
class ProfileTab extends StatelessWidget {
|
|
final VoidCallback? onLogoutSuccess;
|
|
const ProfileTab({super.key, this.onLogoutSuccess});
|
|
|
|
Future<void> _logout(BuildContext context) async {
|
|
await FirebaseAuth.instance.signOut();
|
|
if (onLogoutSuccess != null) {
|
|
onLogoutSuccess!();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final user = FirebaseAuth.instance.currentUser;
|
|
final email = user?.email ?? 'Keine E-Mail gefunden';
|
|
final uid = user?.uid;
|
|
|
|
return Scaffold(
|
|
body: uid == null
|
|
? const Center(child: Text('Nicht eingeloggt'))
|
|
: FutureBuilder<DocumentSnapshot>(
|
|
future: FirebaseFirestore.instance.collection('User').doc(uid).get(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
if (!snapshot.hasData || !snapshot.data!.exists) {
|
|
return const Center(child: Text('Keine Profildaten gefunden'));
|
|
}
|
|
final data = snapshot.data!.data() as Map<String, dynamic>;
|
|
final name = data['name'] ?? 'Unbekannt';
|
|
final role = data['role'] == 'trainer' ? 'Trainer' : 'Spieler';
|
|
final createdAt = (data['createdAt'] is Timestamp)
|
|
? (data['createdAt'] as Timestamp).toDate()
|
|
: null;
|
|
final createdAtStr = createdAt != null
|
|
? '${createdAt.day.toString().padLeft(2, '0')}.${createdAt.month.toString().padLeft(2, '0')}.${createdAt.year}'
|
|
: 'Unbekannt';
|
|
// Beispiel-Benutzerdaten (Statistiken als Demo)
|
|
final Map<String, dynamic> userData = {
|
|
'name': name,
|
|
'level': role,
|
|
'joinedDate': createdAtStr,
|
|
'workoutsCompleted': 42,
|
|
'totalMinutes': 1260,
|
|
};
|
|
|
|
return CustomScrollView(
|
|
slivers: [
|
|
SliverAppBar(
|
|
expandedHeight: 200,
|
|
pinned: true,
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
title: Text(userData['name']),
|
|
background: Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [Colors.blue[700]!, Colors.blue[500]!],
|
|
),
|
|
),
|
|
child: const Center(
|
|
child: Icon(Icons.person, size: 80, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SliverToBoxAdapter(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildInfoCard(
|
|
title: 'Persönliche Informationen',
|
|
child: Column(
|
|
children: [
|
|
_buildInfoRow('E-Mail', email, Icons.email),
|
|
const Divider(),
|
|
_buildInfoRow('Name', name, Icons.person),
|
|
const Divider(),
|
|
_buildInfoRow('Rolle', role, Icons.badge),
|
|
const Divider(),
|
|
_buildInfoRow(
|
|
'Mitglied seit',
|
|
userData['joinedDate'],
|
|
Icons.calendar_today,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
_buildInfoCard(
|
|
title: 'Einstellungen',
|
|
child: Column(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.notifications),
|
|
title: const Text('Benachrichtigungen'),
|
|
trailing: Switch(
|
|
value: true,
|
|
onChanged: (value) {},
|
|
),
|
|
),
|
|
const Divider(),
|
|
ListTile(
|
|
leading: const Icon(Icons.dark_mode),
|
|
title: const Text('Dark Mode'),
|
|
trailing: Switch(
|
|
value: false,
|
|
onChanged: (value) {},
|
|
),
|
|
),
|
|
const Divider(),
|
|
ListTile(
|
|
leading: const Icon(Icons.language),
|
|
title: const Text('Sprache'),
|
|
trailing: const Text('Deutsch'),
|
|
onTap: () {},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Center(
|
|
child: TextButton.icon(
|
|
onPressed: () => _logout(context),
|
|
icon: const Icon(Icons.logout),
|
|
label: const Text('Abmelden'),
|
|
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoCard({required String title, required Widget child}) {
|
|
return Card(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Text(
|
|
title,
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
child,
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoRow(String label, String value, IconData icon) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, color: Colors.blue),
|
|
const SizedBox(width: 16),
|
|
Expanded(child: Text(label)),
|
|
Text(value, style: TextStyle(color: Colors.grey[600])),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|