profileseite fertig incl ändern des profiles,
parent
260d49870b
commit
2314f08308
|
@ -3,6 +3,7 @@ import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../Widgets/bottom_nav_bar.dart';
|
import '../Widgets/bottom_nav_bar.dart';
|
||||||
|
import '../services/global_variables.dart';
|
||||||
|
|
||||||
class ProfileScreen extends StatefulWidget {
|
class ProfileScreen extends StatefulWidget {
|
||||||
final String userId;
|
final String userId;
|
||||||
|
@ -44,33 +45,37 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
final DocumentSnapshot userDoc =
|
final DocumentSnapshot userDoc = await FirebaseFirestore.instance
|
||||||
await FirebaseFirestore.instance.collection('users').doc(widget.userId).get();
|
.collection('users')
|
||||||
|
.doc(widget.userId)
|
||||||
|
.get();
|
||||||
|
|
||||||
if (userDoc == null) {
|
if (userDoc.exists) {
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
name = userDoc.get('name');
|
name = userDoc.get('name');
|
||||||
email = userDoc.get('email');
|
email = userDoc.get('email');
|
||||||
phoneNumber = userDoc.get('phone');
|
phoneNumber = userDoc.get('phone');
|
||||||
imageUrl = userDoc.get('userImage');
|
imageUrl = userDoc.get('userImage');
|
||||||
joinedAt = userDoc.get('createdAt');
|
|
||||||
location = userDoc.get('location');
|
location = userDoc.get('location');
|
||||||
|
|
||||||
_nameController.text = name ?? '';
|
_nameController.text = name ?? '';
|
||||||
_emailController.text = email ?? '';
|
_emailController.text = email ?? '';
|
||||||
_phoneNumberController.text = phoneNumber ?? '';
|
_phoneNumberController.text = phoneNumber ?? '';
|
||||||
_locationController.text = location ?? '';
|
_locationController.text = location ?? '';
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
|
final timestamp = userDoc.get('createdAt');
|
||||||
});
|
});
|
||||||
User? user = _auth.currentUser;
|
User? user = _auth.currentUser;
|
||||||
final _uid = user!.uid;
|
final _uid = user!.uid;
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSameUser = _uid == widget.userId;
|
_isSameUser = _uid == widget.userId;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
print('User not found');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle error
|
// Handle error
|
||||||
|
print('Error: $error');
|
||||||
} finally {
|
} finally {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
|
@ -84,6 +89,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
_isEditing = !_isEditing;
|
_isEditing = !_isEditing;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveChanges() {
|
void _saveChanges() {
|
||||||
|
@ -117,9 +123,25 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
title: Text('Profile'),
|
title: Text('Profile'),
|
||||||
actions: [
|
actions: [
|
||||||
if (_isSameUser)
|
if (_isSameUser)
|
||||||
IconButton(
|
ElevatedButton(
|
||||||
onPressed: _toggleEditMode,
|
onPressed: _saveChanges,
|
||||||
icon: Icon(_isEditing ? Icons.check : Icons.edit),
|
child: Text(_isEditing ? 'Save' : 'Edit'),
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStateProperty.all<Color>(
|
||||||
|
Colors.blue,
|
||||||
|
),
|
||||||
|
foregroundColor: MaterialStateProperty.all<Color>(
|
||||||
|
Colors.white,
|
||||||
|
),
|
||||||
|
padding: MaterialStateProperty.all<EdgeInsets>(
|
||||||
|
EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
|
),
|
||||||
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||||
|
RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -134,14 +156,21 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
|
Image.network(
|
||||||
|
signupUrlImage,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
width: double.infinity,
|
||||||
|
height: double.infinity,
|
||||||
|
),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 40),
|
||||||
Container(
|
Container(
|
||||||
width: MediaQuery.of(context).size.width * 0.4,
|
width: MediaQuery.of(context).size.width ,
|
||||||
height: MediaQuery.of(context).size.width * 0.4,
|
height: MediaQuery.of(context).size.width ,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
|
@ -157,12 +186,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Name:',
|
'Name:',
|
||||||
|
|
Loading…
Reference in New Issue