diff --git a/trainerbox/lib/screens/login_screen.dart b/trainerbox/lib/screens/login_screen.dart index 8cd23d4..b08a53a 100644 --- a/trainerbox/lib/screens/login_screen.dart +++ b/trainerbox/lib/screens/login_screen.dart @@ -14,9 +14,11 @@ class _LoginScreenState extends State { final _formKey = GlobalKey(); final _emailController = TextEditingController(); final _passwordController = TextEditingController(); + final _nameController = TextEditingController(); String? _error; bool _loading = false; bool _isLogin = true; + bool _isTrainer = false; Future _submit() async { setState(() { _loading = true; _error = null; }); @@ -46,6 +48,8 @@ class _LoginScreenState extends State { final uid = cred.user!.uid; await FirebaseFirestore.instance.collection('User').doc(uid).set({ 'email': _emailController.text.trim(), + 'name': _nameController.text.trim(), + 'role': _isTrainer ? 'trainer' : 'player', 'createdAt': FieldValue.serverTimestamp(), }); widget.onLoginSuccess(); @@ -72,6 +76,34 @@ class _LoginScreenState extends State { children: [ Text(_isLogin ? 'Login' : 'Registrieren', style: Theme.of(context).textTheme.headlineMedium), const SizedBox(height: 32), + if (!_isLogin) ...[ + TextFormField( + controller: _nameController, + decoration: const InputDecoration(labelText: 'Name'), + validator: (v) => v != null && v.trim().isNotEmpty ? null : 'Name angeben', + ), + const SizedBox(height: 16), + Row( + children: [ + Checkbox( + value: _isTrainer, + onChanged: (v) { + setState(() { _isTrainer = v ?? false; }); + }, + ), + const Text('Ich bin Trainer'), + const SizedBox(width: 16), + Checkbox( + value: !_isTrainer, + onChanged: (v) { + setState(() { _isTrainer = !(v ?? false); }); + }, + ), + const Text('Ich bin Spieler'), + ], + ), + const SizedBox(height: 16), + ], TextFormField( controller: _emailController, decoration: const InputDecoration(labelText: 'E-Mail'), diff --git a/trainerbox/lib/screens/profile_tab.dart b/trainerbox/lib/screens/profile_tab.dart index 7123c5c..1a17671 100644 --- a/trainerbox/lib/screens/profile_tab.dart +++ b/trainerbox/lib/screens/profile_tab.dart @@ -1,5 +1,6 @@ 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; @@ -16,125 +17,151 @@ class ProfileTab extends StatelessWidget { Widget build(BuildContext context) { final user = FirebaseAuth.instance.currentUser; final email = user?.email ?? 'Keine E-Mail gefunden'; - // Beispiel-Benutzerdaten (kannst du später dynamisch machen) - final Map userData = { - 'name': 'Max Mustermann', - 'level': 'Fortgeschritten', - 'joinedDate': '01.01.2024', - 'workoutsCompleted': 42, - 'totalMinutes': 1260, - }; + final uid = user?.uid; return Scaffold( - body: 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: 'Statistiken', - child: Column( - children: [ - _buildStatisticRow( - 'Trainings absolviert', - userData['workoutsCompleted'].toString(), - Icons.fitness_center, - ), - const Divider(), - _buildStatisticRow( - 'Gesamtzeit', - '${userData['totalMinutes']} Minuten', - Icons.timer, - ), - ], - ), - ), - const SizedBox(height: 16), - _buildInfoCard( - title: 'Persönliche Informationen', - child: Column( - children: [ - _buildInfoRow('E-Mail', email, Icons.email), - const Divider(), - _buildInfoRow('Level', userData['level'], Icons.star), - 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) {}, + body: uid == null + ? const Center(child: Text('Nicht eingeloggt')) + : FutureBuilder( + 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; + 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 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), ), ), - 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), + SliverToBoxAdapter( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildInfoCard( + title: 'Statistiken', + child: Column( + children: [ + _buildStatisticRow( + 'Trainings absolviert', + userData['workoutsCompleted'].toString(), + Icons.fitness_center, + ), + const Divider(), + _buildStatisticRow( + 'Gesamtzeit', + '${userData['totalMinutes']} Minuten', + Icons.timer, + ), + ], + ), + ), + const SizedBox(height: 16), + _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), + ), + ), + ], + ), + ), ), - ), - ], - ), + ], + ); + }, ), - ), - ], - ), ); }