Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 닉네임 수정 #51

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/models/content_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ContentModel with _$ContentModel {
String? contentUrl,
String? contentMemo,
required String contentName,
String? folderName,
required List<HashtagModel> contentHashTag,
}) = _ContentModel;

Expand Down
1 change: 1 addition & 0 deletions lib/repositories/hashtag_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HashtagRepository implements IHashtagRepository {
'contentUrl': e['contentUrl'] ?? '',
'contentMemo': e['memo'],
'contentName': e['name'],
'folderName': e['folderName'],
'contentHashTag': e['hashTags'],
}),
)
Expand Down
7 changes: 5 additions & 2 deletions lib/screens/add_content/add_image_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AddImageContent extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
var hashtagAsync = ref.watch(hashtagProvider);
var loading = useState(false);
var picker = ImagePicker();
var imageFile = useState<XFile?>(null);

Expand Down Expand Up @@ -76,6 +77,7 @@ class AddImageContent extends HookConsumerWidget {
return;
}

loading.value = true;
String base64Image = await xFileToBase64(imageFile.value!);

var selectTag = [];
Expand Down Expand Up @@ -108,6 +110,8 @@ class AddImageContent extends HookConsumerWidget {
snackbar.alert(
context, kDebugMode ? error.toString() : '오류가 발생했어요 다시 시도해주세요.');
}
} finally {
loading.value = false;
}
}

Expand Down Expand Up @@ -233,8 +237,7 @@ class AddImageContent extends HookConsumerWidget {
bottom: 0,
width: MediaQuery.of(context).size.width,
child: Button(
// loading: loading.value,
// disabled: disableSubmit.value,
loading: loading.value,
onPress: completeAddContent,
backgroundColor: AppColors.primaryColor,
text: '완료',
Expand Down
17 changes: 5 additions & 12 deletions lib/screens/add_content/add_link_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AddLinkContent extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
var hashtagAsync = ref.watch(hashtagProvider);
var loading = useState(false);
var picker = ImagePicker();
var imageFile = useState<XFile?>(null);
var receiveImage = useState<String?>(null);
Expand Down Expand Up @@ -87,6 +88,7 @@ class AddLinkContent extends HookConsumerWidget {

return;
}
loading.value = true;

String base64Image = await xFileToBase64(imageFile.value!);

Expand Down Expand Up @@ -121,6 +123,8 @@ class AddLinkContent extends HookConsumerWidget {
snackbar.alert(
context, kDebugMode ? error.toString() : '오류가 발생했어요 다시 시도해주세요.');
}
} finally {
loading.value = false;
}
}

Expand Down Expand Up @@ -239,14 +243,6 @@ class AddLinkContent extends HookConsumerWidget {
style: H4TextStyle(),
),
const SizedBox(height: 5),
// receiveImage.value != null
// ? Image.network(
// receiveImage.value!,
// width: double.infinity,
// height: 200,
// fit: BoxFit.cover,
// )
// : const SizedBox(),
SizedBox(
width: double.infinity,
height: 85,
Expand All @@ -268,8 +264,6 @@ class AddLinkContent extends HookConsumerWidget {
width: 0.5,
),
color: AppColors.textInputBackground,
// image:
// DecorationImage(image: Assets.moaBannerImg),
),
child: InkWell(
onTap: () => pickImage(
Expand Down Expand Up @@ -330,8 +324,7 @@ class AddLinkContent extends HookConsumerWidget {
bottom: 0,
width: MediaQuery.of(context).size.width,
child: Button(
// loading: loading.value,
// disabled: disableSubmit.value,
loading: loading.value,
onPress: completeAddContent,
backgroundColor: AppColors.primaryColor,
text: '완료',
Expand Down
16 changes: 12 additions & 4 deletions lib/screens/home/tab_view/folder_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:moa_app/providers/folder_view_provider.dart';
import 'package:moa_app/repositories/folder_repository.dart';
import 'package:moa_app/screens/home/home.dart';
import 'package:moa_app/utils/general.dart';
import 'package:moa_app/utils/logger.dart';
import 'package:moa_app/utils/router_provider.dart';
import 'package:moa_app/widgets/loading_indicator.dart';
import 'package:moa_app/widgets/moa_widgets/add_folder.dart';
Expand Down Expand Up @@ -61,8 +62,9 @@ class FolderTabView extends HookConsumerWidget {
onPressed: () async {
try {
await FolderRepository.instance.editFolderName(
currentFolderName: folderName,
editFolderName: updatedContentName.value);
currentFolderName: folderName,
editFolderName: updatedContentName.value,
);
await ref.read(folderViewProvider.notifier).editFolderName(
currentFolderName: folderName,
editFolderName: updatedContentName.value,
Expand All @@ -72,10 +74,16 @@ class FolderTabView extends HookConsumerWidget {
context.pop();
}
} on DioError catch (error) {
// todo 폴더 중복 에러 처리
logger.d(error);
// 폴더 중복 에러 처리
if (error.response!.statusCode == 409) {
snackbar.alert(context, '이미 가지고 있는 폴더이름이에요!');
snackbar.alert(context,
kDebugMode ? error.toString() : '이미 가지고 있는 폴더이름이에요');
return;
}

snackbar.alert(context,
kDebugMode ? error.toString() : '오류가 발생했어요 다시 시도해주세요.');
}
},
),
Expand Down
10 changes: 7 additions & 3 deletions lib/screens/home/tab_view/hashtag_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class HashtagTabView extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
var width = MediaQuery.of(context).size.width;

void goContentView(String contentId) {
void goContentView(
{required String contentId, required String folderName}) {
context.go(
'${GoRoutes.content.fullPath}/$contentId',
extra: ContentView(id: contentId, folderName: 'folderName'),
extra: ContentView(id: contentId, folderName: folderName),
);
}

Expand Down Expand Up @@ -118,7 +119,10 @@ class HashtagTabView extends HookConsumerWidget {
return InkWell(
splashColor: Colors.transparent,
borderRadius: BorderRadius.circular(10),
onTap: () => goContentView(item.contentId),
onTap: () => goContentView(
contentId: item.contentId,
folderName: item.folderName ?? '',
),
child: Column(
children: [
item.contentImageUrl == ''
Expand Down
115 changes: 81 additions & 34 deletions lib/screens/setting/setting.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:moa_app/constants/color_constants.dart';
Expand All @@ -11,17 +12,22 @@ import 'package:moa_app/repositories/user_repository.dart';
import 'package:moa_app/screens/setting/widgets/setting_list_tile.dart';
import 'package:moa_app/utils/router_provider.dart';
import 'package:moa_app/widgets/alert_dialog.dart';
import 'package:moa_app/widgets/button.dart';
import 'package:moa_app/widgets/edit_text.dart';
import 'package:moa_app/widgets/snackbar.dart';

class Setting extends HookConsumerWidget {
const Setting({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
var editNicknameMode = useState(false);
var nickname = useState('');
var loading = useState(false);
void pickImage() {}

void goEditMyType() {
context.go('${GoRoutes.setting.fullPath}/${GoRoutes.editContent.path}');
// context.go('${GoRoutes.setting.fullPath}/${GoRoutes.editContent.path}');
}

void handleContact() {}
Expand Down Expand Up @@ -69,6 +75,23 @@ class Setting extends HookConsumerWidget {
);
}

void changeEditNicknameMode() {
editNicknameMode.value = true;
}

void editMyNickname({required String nickname}) async {
try {
loading.value = true;
await UserRepository.instance.editUserNickname(nickname: nickname);
} catch (e) {
snackbar.alert(
context, kDebugMode ? e.toString() : '닉네임 수정에 실패했습니다 다시 시도해주세요.');
} finally {
editNicknameMode.value = false;
loading.value = false;
}
}

return Scaffold(
body: SafeArea(
child: SizedBox(
Expand Down Expand Up @@ -107,42 +130,66 @@ class Setting extends HookConsumerWidget {
children: [
GestureDetector(
onTap: pickImage,
child: Stack(
children: [
Image(
width: 78,
height: 69,
image: Assets.profileMoa,
),
// const CircleAvatar(
// radius: 50,
// backgroundImage: NetworkImage(
// 'https://avatars.githubusercontent.com/u/73378472?v=4'),
// ),
// Positioned(
// bottom: 0,
// right: 0,
// child: Container(
// width: 25,
// height: 25,
// padding: const EdgeInsets.all(6),
// decoration: BoxDecoration(
// color: AppColors.blackColor,
// borderRadius: BorderRadius.circular(50),
// ),
// child: Image(
// color: AppColors.whiteColor,
// image: Assets.pencil,
// ),
// ),
// )
],
child: Image(
width: 78,
height: 69,
image: Assets.profileMoa,
),
),
const SizedBox(height: 5),
Text(
userInfo?.nickname ?? '',
style: const H2TextStyle(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(width: 20),
editNicknameMode.value
? EditText(
inputPadding: const EdgeInsets.symmetric(
horizontal: 10),
width: 100,
height: 30,
onChanged: (value) {
nickname.value = value;
},
hintText: userInfo?.nickname,
)
: InkWell(
overlayColor: MaterialStateProperty.all(
AppColors.whiteColor),
borderRadius: const BorderRadius.all(
Radius.circular(2)),
onTap: changeEditNicknameMode,
child: Text(
userInfo?.nickname ?? '',
style: const H2TextStyle(),
),
),
const SizedBox(width: 5),
editNicknameMode.value
? Button(
loading: loading.value,
disabled: nickname.value == '',
onPress: () => editMyNickname(
nickname: nickname.value,
),
height: 30,
text: '수정',
textStyle: const Body1TextStyle(),
)
: CircleIconButton(
width: 20,
height: 20,
splashColor:
AppColors.whiteColor.withOpacity(0.3),
backgroundColor: AppColors.blackColor,
onPressed: changeEditNicknameMode,
icon: Image(
width: 10,
height: 10,
color: AppColors.whiteColor,
image: Assets.pencil,
),
),
],
),
const SizedBox(height: 3),
Text(
Expand Down
7 changes: 6 additions & 1 deletion lib/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ class CircleIconButton extends StatefulWidget {
this.backgroundColor = AppColors.textInputBackground,
this.width,
this.height,
this.splashColor,
});
final Function() onPressed;
final Widget icon;
final Color? backgroundColor;
final double? width;
final double? height;
final Color? splashColor;

@override
State<CircleIconButton> createState() => _CircleIconButtonState();
Expand All @@ -216,7 +218,10 @@ class _CircleIconButtonState extends State<CircleIconButton> {
), // <-- Button color
overlayColor: MaterialStateProperty.resolveWith<Color?>((states) {
if (states.contains(MaterialState.pressed)) {
return Colors.black.withOpacity(0.1);
if (widget.splashColor != null) {
return widget.splashColor;
}
return AppColors.blackColor.withOpacity(0.1);
}
return null; // <-- Splash color
}),
Expand Down
Loading
Loading