Skip to content

Commit

Permalink
닉네임 프로바이더 + 닉네임 위젯 생성 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwson-automation authored Jul 23, 2024
2 parents 8a59742 + 9395e0e commit f0fc05d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
16 changes: 16 additions & 0 deletions lib/providers/MyPageNameProvider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final myPageNicknameProvider = StreamProvider<String>((ref) {
final firestore = FirebaseFirestore.instance;
final userId = FirebaseAuth.instance.currentUser!.uid;

return firestore
.collection('users')
.doc(userId)
.snapshots()
.map((snapshot) {
return snapshot['name'] as String;
});
});
11 changes: 4 additions & 7 deletions lib/screens/mypage/MyPageScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import '../../providers/camera/FirebaseStoreServiceProvider.dart';
import '../../providers/camera/fireStorageServiceProvider.dart';
import '../../providers/user/FirebaseAuthServiceProvider.dart';
import '../../providers/user/ProfileImageProvider.dart';
import '../../utils/AppStrings.dart';
import '../../widgets/CustomDividerWidget.dart';
import '../../widgets/NickNameTextWidget.dart';
import '../SettingScreen.dart';
import 'camera/SettingsBottomSheet.dart';

Expand All @@ -27,7 +29,7 @@ class MyPageScreen extends ConsumerWidget {

return Scaffold(
appBar: AppBar(
title: const Text('My Page'),
title: const Text(AppStrings.myPageTitle),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
Expand All @@ -41,11 +43,7 @@ class MyPageScreen extends ConsumerWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"userID or userNickName",
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
),
NickNameTextWidget(),
Text("Google 로그인을 사용 중 입니다.")
],
),
Expand Down Expand Up @@ -324,4 +322,3 @@ Widget _uploadProfileImageButtons(FirestoreService firestoreService,
icon: const Icon(Icons.settings),
);
}

23 changes: 14 additions & 9 deletions lib/utils/AppStrings.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
class AppStrings {
static const String appTitle = '블루베리 플러터 템플릿';

//ChatPage.dart
static const String lessonChatScreenTitle = '채팅';
//NickNameTextWidget.dart
static const String nickNameTextWidgetdefaultNickName = '닉네임';
static const String nickNameTextWidgetError = '오류';


//ShoppingPageSample.dart
static const String shoppingPageTitle = '쇼핑 페이지';
static const String shoppingPageTitle1 = '이 제품들을 찾고 있나요?';
static const String shoppingPageSubTitle1 = '항상 최고의 블루베리를 찾아드립니다.';
static const String shoppingPageTitle2 = '신상품';
static const String shoppingPageSubTitle2 = '최신 제품을 확인하세요.';

//DeleteMyPage.dart
//MyPageScreen.dart
static const String myPageTitle = '내 페이지';
static const String loginButtonText = '로그인';
static const String logoutButtonText = '로그아웃';
Expand All @@ -21,6 +17,15 @@ class AppStrings {
static const String okButtonText = '확인';
static const String loggedInMessage = '로그인 되었습니다.';
static const String passwordForgot = '비밀번호를 잊어버렸나요?';
//ChatPage.dart
static const String lessonChatScreenTitle = '채팅';

//ShoppingPageSample.dart
static const String shoppingPageTitle = '쇼핑 페이지';
static const String shoppingPageTitle1 = '이 제품들을 찾고 있나요?';
static const String shoppingPageSubTitle1 = '항상 최고의 블루베리를 찾아드립니다.';
static const String shoppingPageTitle2 = '신상품';
static const String shoppingPageSubTitle2 = '최신 제품을 확인하세요.';

//SignUpDialog.dart
static const String signUpPageTitle = '회원가입';
Expand Down
22 changes: 22 additions & 0 deletions lib/widgets/NickNameTextWidget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../providers/MyPageNameProvider.dart';
import '../utils/AppStrings.dart';

class NickNameTextWidget extends ConsumerWidget {
const NickNameTextWidget({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final nickname = ref.watch(myPageNicknameProvider);
return nickname.when(
data: (name) => Text(
name,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
loading: () => Text(''),
error: (e, s) => const Text(AppStrings.nickNameTextWidgetError),
);
}
}

0 comments on commit f0fc05d

Please sign in to comment.