generated from jwson-automation/blueberry_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jungwoo <108061510+jwson-automation@users.noreply.github.com>
- Loading branch information
1 parent
b8cc023
commit 2da5e49
Showing
12 changed files
with
319 additions
and
144 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
lib/feature/friendsList/provider/FriendsListImageProvider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
// 친구목록 이미지 URL을 제공하는 Provider | ||
final friendsListImageProvider = | ||
FutureProvider.family<String, String>((ref, imageName) async { | ||
final storageRef = FirebaseStorage.instance.ref('profileimage/$imageName'); | ||
final downloadUrl = await storageRef.getDownloadURL(); | ||
return downloadUrl; | ||
}); |
96 changes: 74 additions & 22 deletions
96
lib/feature/friendsList/provider/FriendsListProvider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,93 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import '../../../model/FriendModel.dart'; | ||
import '../../../utils/AppStrings.dart'; | ||
import '../../../utils/Talker.dart'; | ||
import '../../userreport/provider/UserReportBottomSheetWidget.dart'; | ||
|
||
// 친구 목록을 제공하는 Provider | ||
// 친구목록을 제공하는 Provider | ||
final friendsListProvider = StreamProvider<List<FriendModel>>((ref) { | ||
final firestore = FirebaseFirestore.instance; | ||
|
||
const userId = 'eztqDqrvEXDc8nqnnrB8'; // 로그인을 가정한 임시 유저 ID | ||
|
||
return firestore | ||
.collection('users_test') | ||
.doc(userId) | ||
.collection('friends') | ||
.snapshots() | ||
.map((snapshot) { | ||
return snapshot.docs.map((doc) { | ||
final data = doc.data(); | ||
return FriendModel.fromJson({ | ||
...data, | ||
'lastConnect': | ||
(data['lastConnect'] as Timestamp).toDate().toIso8601String(), | ||
}); | ||
}).toList(); | ||
.asyncMap((snapshot) async { | ||
final friendModels = await Future.wait(snapshot.docs.map((doc) async { | ||
final userID = doc['userID'] as String; | ||
final userDoc = await firestore.collection('users_test').doc(userID).get(); | ||
|
||
if (userDoc.exists) { | ||
return FriendModel.fromJson(userDoc.data()!); | ||
} else { | ||
throw Exception(AppStrings.userNotFoundErrorMessage); | ||
} | ||
}).toList()); | ||
|
||
return friendModels; | ||
}); | ||
}); | ||
|
||
// 친구목록 이미지 URL을 제공하는 Provider | ||
final friendsListImageProvider = | ||
FutureProvider.family<String, String>((ref, imageName) async { | ||
final ref = FirebaseStorage.instance.ref('friends-profile/$imageName'); | ||
return await ref.getDownloadURL(); | ||
final deleteFriendProvider = | ||
Provider<Future<void> Function(BuildContext, FriendModel)>((ref) { | ||
return (BuildContext context, FriendModel friend) async { | ||
final firestore = FirebaseFirestore.instance; | ||
const userId = 'eztqDqrvEXDc8nqnnrB8'; // 로그인을 가정한 임시 유저 ID | ||
|
||
await firestore | ||
.collection('users_test') | ||
.doc(userId) | ||
.collection('friends') | ||
.doc(friend.userID) | ||
.delete(); | ||
|
||
ref.invalidate(friendsListProvider); | ||
|
||
if (context.mounted) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text(AppStrings.friendDeleteSuccessMessage)), | ||
); | ||
} | ||
}; | ||
}); | ||
|
||
// /// 이미지 URL을 제공하는 공용 Provider | ||
// final imageProvider = FutureProvider.family<String, String>((ref, imagePath) async { | ||
// final ref = FirebaseStorage.instance.ref(imagePath); | ||
// return await ref.getDownloadURL(); | ||
// }); | ||
|
||
|
||
// ui 팝업 메뉴 선택시 처리하는 함수 | ||
void handleMenuSelection( | ||
BuildContext context, WidgetRef ref, int value, FriendModel friend) async { | ||
switch (value) { | ||
case 1: | ||
// 삭제 | ||
final deleteFriend = ref.read(deleteFriendProvider); | ||
Navigator.of(context).pop(); | ||
await deleteFriend(context, friend); | ||
break; | ||
case 2: | ||
Navigator.of(context).pop(); | ||
if (context.mounted) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('차단 기능이 아직 구현되지 않았습니다.')), | ||
); | ||
} | ||
break; | ||
case 3: | ||
// 신고 | ||
Navigator.of(context).pop(); | ||
showModalBottomSheet( | ||
context: context, | ||
isScrollControlled: true, | ||
shape: const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)), | ||
), | ||
builder: (context) => UserReportBottomSheetWidget(friend: friend), | ||
); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/feature/friendsList/widget/FriendBottomSheetLauncher.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../model/FriendModel.dart'; | ||
import 'FriendBottomSheet.dart'; | ||
|
||
class FriendBottomSheetLauncher { | ||
static void show({ | ||
required BuildContext context, | ||
required FriendModel friend, | ||
required String imageUrl, | ||
}) { | ||
showModalBottomSheet( | ||
context: context, | ||
isScrollControlled: true, | ||
shape: const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.vertical( | ||
top: Radius.circular(25.0), | ||
), | ||
), | ||
builder: (context) => FriendBottomSheetWidget( | ||
friend: friend, | ||
imageUrl: imageUrl, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.