HseyinAkkaya
Bir değişiklik yok hala aynı
fyt19

- Sep 16, 2023
- Joined Sep 15, 2023
- In Profil page
- In Profil page
- Edited
import 'package:flutter/material.dart'; import 'package:login_screen/screens/alt_menu.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; class ProfilePage extends StatefulWidget { const ProfilePage({Key? key}) : super(key: key); @override _ProfilePageState createState() => _ProfilePageState(); } class _ProfilePageState extends State<ProfilePage> { int _selectedIndex = 3; // Varsayılan olarak Profil sayfası seçili String? name = ''; String? email = ''; String? hospital = ''; String? userName = FirebaseAuth.instance.currentUser?.displayName; // Kullanıcı adını saklamak için değişken String userHospital = ''; // Hastane bilgisini saklamak için değişken Future _getDataFromDatabase() async { await FirebaseFirestore.instance .collection("users") .doc(FirebaseAuth.instance.currentUser!.uid) .get() .then((snapshot) async { if (snapshot.exists) { setState(() { email = snapshot.data()!["mail"]; name = snapshot.data()!["name"]; hospital = snapshot.data()!["hospital"]; }); } }); } void _onItemTapped(int index1) { setState(() { _selectedIndex = index1; }); } @override void initState() { super.initState(); _loadUserData(); } Future<void> _loadUserData() async { User? user = FirebaseAuth.instance.currentUser; if (user != null) { // Firebase Firestore'dan kullanıcı verilerini çekme DocumentSnapshot userSnapshot = await FirebaseFirestore.instance .collection('users') .doc(user.uid) .get(); if (userSnapshot.exists) { setState(() { userName = userSnapshot['name'] ?? ''; // Firestore'daki 'name' alanından adı çekme userHospital = userSnapshot['hospital'] ?? ''; // Firestore'daki 'hospital' alanından hastane bilgisini çekme }); } } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Profil'), backgroundColor: Color.fromARGB(248, 221, 133, 1), ), /* backgroundColor: Colors.white, */ body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ SizedBox(height: 170.0), ProfileInfoCard( title: 'Adı:', /* data: FirebaseAuth.instance.currentUser?.displayName ?? '', */ data: name!, ), ProfileInfoCard( title: 'E-posta:', data: FirebaseAuth.instance.currentUser?.email ?? '', /* data: email!, */ ), ProfileInfoCard( title: 'Hastane:', data: hospital!, /* data: userHospital, */ ), ], ), ), bottomNavigationBar: BottomNavigationMenu( selectedIndex: _selectedIndex, onItemTapped: _onItemTapped, ), ); } } class ProfileInfoCard extends StatelessWidget { final String title; final String data; const ProfileInfoCard({ required this.title, required this.data, }); @override Widget build(BuildContext context) { return Card( elevation: 2.0, margin: EdgeInsets.symmetric(vertical: 8.0), child: Padding( padding: EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16.0, ), ), SizedBox(height: 8.0), Text( data, style: TextStyle(fontSize: 14.0), ), ], ), ), ); } }
kod kısmı bu şekilde
- In Profil page
- Edited
aşağıda kod kısmım var bu şekilde bilgileri profil sayfasında göstermek istiyorum ama olmuyor, yardımcı olursanız sevinirim.
String? email = ''; String? hospital = ''; Future _getDataFromDatabase() async { await FirebaseFirestore.instance .collection("users") .doc(FirebaseAuth.instance.currentUser!.uid) .get() .then((snapshot) async { if (snapshot.exists) { setState(() { email = snapshot.data()!["mail"]; name = snapshot.data()!["name"]; hospital = snapshot.data()!["hospital"]; }); } }); } body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ SizedBox(height: 170.0), ProfileInfoCard( title: 'Adı:', /* data: FirebaseAuth.instance.currentUser?.displayName ?? '', */ data: name!, ), ProfileInfoCard( title: 'E-posta:', /* data: FirebaseAuth.instance.currentUser?.email ?? '', */ data: email!, ), ProfileInfoCard( title: 'Hastane:', data: hospital!, /* data: userHospital, */ ), Text( 'Name: ' + name!, ) ], ), ),