Skip to content

Commit

Permalink
griş yapılınca drawer widgetdaki isim değişir, sosyal medya hesapları…
Browse files Browse the repository at this point in the history
… görünür
  • Loading branch information
ozlemkayyaa committed Feb 28, 2024
1 parent 1e3e9bc commit 733165a
Show file tree
Hide file tree
Showing 9,266 changed files with 1,106,501 additions and 64 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/api/blocs/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final UserModel userModel =
await _userRepository.fetchCurrentUser(UserModel());
final String? userName = userModel.name;
emit(Authenticated(user: _firebaseAuth.currentUser, userName: userName));
final String? surName = userModel.surname;
emit(Authenticated(
user: _firebaseAuth.currentUser,
userName: userName,
surName: surName));
} on FirebaseAuthException catch (e) {
emit(NotAuthenticated(errorMessage: e.message));
}
Expand Down
5 changes: 3 additions & 2 deletions lib/api/blocs/auth_bloc/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class NotAuthenticated extends AuthState {

class Authenticated extends AuthState {
User? user;
String? userName; // Kullanıcı adını tutmak için
String? userName;
String? surName; // Kullanıcı adını tutmak için

Authenticated({this.user, this.userName});
Authenticated({this.user, this.userName, this.surName});
}
42 changes: 39 additions & 3 deletions lib/api/blocs/profile_bloc/profile_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
on<FetchProfileEvent>(_onFetchProfile);
on<UpdateProfileEvent>(_onUpdateProfile);
on<UploadPhotoEvent>(_onUploadPhoto);
on<UpdateSocialMediaListEvent>(_onUpdateSocialMediaListEvent);
on<UpdateLanguageEvent>(_onUpdateLanguageEvent);
}

// Profil Getir
Expand All @@ -24,7 +26,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
emit(ProfileLoading());
try {
final user = await _userRepository.fetchCurrentUser(UserModel());
emit(ProfileLoaded(userModel: user));
emit(ProfileLoaded(
userModel: user, selectedSocialMedia: [], selectedLanguage: []));
} catch (e) {
emit(ProfileError(errorMessage: e.toString()));
}
Expand All @@ -43,14 +46,47 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
}
}

// Fotoğrafı Güncelle
Future<void> _onUploadPhoto(
UploadPhotoEvent event, Emitter<ProfileState> emit) async {
emit(ProfileLoading());
try {
await _storageRepository.uploadPhoto(event.photo);
emit(ProfileUpdated());
final currentState = state;
if (currentState is ProfileLoaded) {
// Fotoğrafı depola (örneğin Firebase Storage'a yükle)
final photoUrl = await _storageRepository.uploadPhoto(event.photo);

// Kullanıcı modelini fotoğraf URL'si ile güncelle
final updatedUser =
currentState.userModel.copyWith(profilePhoto: photoUrl);

// Güncellenmiş kullanıcı modeliyle ProfileLoaded durumunu güncelle
emit(ProfileLoaded(
userModel: updatedUser,
selectedSocialMedia: currentState.selectedSocialMedia,
selectedLanguage: currentState.selectedLanguage));
}
} catch (e) {
emit(ProfileError(errorMessage: e.toString()));
}
}

// Sosyal Medya Hesaplarını görünür yap
void _onUpdateSocialMediaListEvent(
UpdateSocialMediaListEvent event, Emitter<ProfileState> emit) {
final currentState = state;
if (currentState is ProfileLoaded) {
emit(currentState.copyWith(
selectedSocialMedia: event.selectedSocialMedia));
}
}

// Yabancı Dil Seç
void _onUpdateLanguageEvent(
UpdateLanguageEvent event, Emitter<ProfileState> emit) {
final currentState = state;
if (currentState is ProfileLoaded) {
emit(currentState.copyWith(selectedLanguage: event.selectedLanguage));
}
}
}
18 changes: 17 additions & 1 deletion lib/api/blocs/profile_bloc/profile_event.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';

import 'package:tobeto/model/user_model.dart';
import 'package:tobeto/screens/profile_create/model/language_model.dart';
import 'package:tobeto/screens/profile_create/model/social_media_model.dart';

abstract class ProfileEvent {}

Expand All @@ -18,9 +20,23 @@ class UpdateProfileEvent extends ProfileEvent {
});
}

// Profil Fotoğradını Yükle
// Profil Fotoğrafını Yükle
class UploadPhotoEvent extends ProfileEvent {
final File photo;

UploadPhotoEvent({required this.photo});
}

// Sosyal Medya Hesabını Seç
class UpdateSocialMediaListEvent extends ProfileEvent {
final List<SocialMediaData> selectedSocialMedia;

UpdateSocialMediaListEvent(this.selectedSocialMedia);
}

// Yabancı Dil Seç
class UpdateLanguageEvent extends ProfileEvent {
final List<LanguageData> selectedLanguage;

UpdateLanguageEvent(this.selectedLanguage);
}
33 changes: 24 additions & 9 deletions lib/api/blocs/profile_bloc/profile_state.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
import 'package:tobeto/model/user_model.dart';
import 'package:tobeto/screens/profile_create/model/language_model.dart';
import 'package:tobeto/screens/profile_create/model/social_media_model.dart';

abstract class ProfileState {}

class ProfileInitial extends ProfileState {}

// İstek Atılıyor, Yükleniyor
class ProfileLoading extends ProfileState {
// Circular progress indicator
}
class ProfileLoading extends ProfileState {}

// Yüklendi, Profil bilgileri ekranda gözükür.
class ProfileLoaded extends ProfileState {
final UserModel userModel;
ProfileLoaded({required this.userModel});
final List<SocialMediaData> selectedSocialMedia;
final List<LanguageData> selectedLanguage;

ProfileLoaded({
required this.userModel,
required this.selectedSocialMedia,
required this.selectedLanguage,
});

ProfileLoaded copyWith({
UserModel? userModel,
List<SocialMediaData>? selectedSocialMedia,
List<LanguageData>? selectedLanguage,
}) {
return ProfileLoaded(
userModel: userModel ?? this.userModel,
selectedSocialMedia: selectedSocialMedia ?? this.selectedSocialMedia,
selectedLanguage: selectedLanguage ?? this.selectedLanguage,
);
}
}

// Veri Yoksa
class ProfileError extends ProfileState {
String errorMessage;

ProfileError({
required this.errorMessage,
});
}

// Profil güncellenirse

class ProfileUpdated extends ProfileState {}
38 changes: 38 additions & 0 deletions lib/model/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,42 @@ class UserModel {
'education': education,
};
}

UserModel copyWith({
String? userId,
String? name,
String? surname,
String? description,
String? github,
String? instagram,
String? linkedin,
String? email,
String? phone,
String? profilePhoto,
DateTime? dateOfBirth,
String? tcNo,
String? country,
String? city,
String? address,
String? education,
}) {
return UserModel(
userId: userId ?? this.userId,
name: name ?? this.name,
surname: surname ?? this.surname,
description: description ?? this.description,
github: github ?? this.github,
instagram: instagram ?? this.instagram,
linkedin: linkedin ?? this.linkedin,
email: email ?? this.email,
phone: phone ?? this.phone,
profilePhoto: profilePhoto ?? this.profilePhoto,
dateOfBirth: dateOfBirth ?? this.dateOfBirth,
tcNo: tcNo ?? this.tcNo,
country: country ?? this.country,
city: city ?? this.city,
address: address ?? this.address,
education: education ?? this.education,
);
}
}
46 changes: 28 additions & 18 deletions lib/screens/home/widgets/drawer_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:iconsax/iconsax.dart';
import 'package:tobeto/api/blocs/auth_bloc/auth_bloc.dart';
import 'package:tobeto/api/blocs/auth_bloc/auth_event.dart';
import 'package:tobeto/api/blocs/auth_bloc/auth_state.dart';
import 'package:tobeto/screens/contact/contact_screen.dart';
import 'package:tobeto/screens/team/team_screen.dart';
import 'package:tobeto/navigation_menu.dart';
Expand Down Expand Up @@ -147,26 +148,35 @@ class DrawerWidget extends StatelessWidget {

// Profil Kısmı
const SizedBox(height: TSizes.spaceBtwSections),
ListTile(
title: Container(
padding: const EdgeInsets.all(TSizes.defaultSpace),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
color: dark ? TColors.darkGrey : TColors.grey),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
TTexts.profileName,
style: Theme.of(context).textTheme.bodyMedium,
BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
if (state is Authenticated && state.userName != null) {
return ListTile(
title: Container(
padding: const EdgeInsets.all(TSizes.defaultSpace),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
color: dark ? TColors.darkGrey : TColors.grey),
),
const Icon(
Iconsax.profile_circle,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${state.userName!} ${state.surName!}',
style: Theme.of(context).textTheme.bodyMedium,
),
const Icon(
Iconsax.profile_circle,
),
],
),
]),
),
),
);
} else {
return const SizedBox();
}
},
),

// 2024 Tobeto
Expand Down
Loading

0 comments on commit 733165a

Please sign in to comment.