Skip to content

Commit

Permalink
Merge pull request #155 from Alpha-Damyo/Feature/#125-ContributionScreen
Browse files Browse the repository at this point in the history
Feature/#125 login check
  • Loading branch information
choichangyeon authored Jun 9, 2024
2 parents 9c67ec8 + 317982e commit 56026b8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 38 deletions.
9 changes: 6 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:damyo/screens/home/challenge/challengedetail_screen.dart';
import 'package:damyo/screens/home/challenge/challengevote_screen.dart';
import 'package:damyo/screens/home/home_screen.dart';
import 'package:damyo/screens/home/inform/inform_screen.dart';
import 'package:damyo/screens/home/map/search/search_screen.dart';
import 'package:damyo/screens/home/map/somking_area/review/write_review_screen.dart';
import 'package:damyo/screens/home/map/somking_area/smoking_area_info_screen.dart';
import 'package:damyo/screens/home/mypage/in_mypage/achievement_screen.dart';
Expand Down Expand Up @@ -213,7 +212,10 @@ final GoRouter router = GoRouter(
GoRoute(
name: 'login',
path: 'login',
builder: (context, state) => const LoginScreen(),
builder: (context, state){
final function = state.extra as VoidCallback;
return LoginScreen(update: function);
},
routes: [
GoRoute(
name: 'signup',
Expand All @@ -240,7 +242,8 @@ final GoRouter router = GoRouter(
name: 'update_profile',
path: 'update_profile',
builder: (context, state) {
return const UpdateprofileScreen();
final function = state.extra as VoidCallback;
return UpdateprofileScreen(update: function,);
},
),
GoRoute(
Expand Down
55 changes: 38 additions & 17 deletions lib/screens/home/mypage/in_mypage/achievement_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:damyo/models/userinfo/user_info_model.dart';
import 'package:damyo/screens/home/mypage/in_mypage/updateprofile_screen.dart';
import 'package:damyo/services/user_controller_service.dart';
Expand All @@ -22,6 +24,7 @@ class _AchievementScreen extends State<AchievementScreen> {
double? contributionPecentage;
String? profileUrl;
String? name;
bool _isLoading = true;

// 유저 정보를 가져오는 함수
Future<UserInfoModel?> getUser() async {
Expand All @@ -43,8 +46,17 @@ class _AchievementScreen extends State<AchievementScreen> {
}
}

Future<void> _loadData(int term) async {
Timer(Duration(milliseconds: term), () {
setState(() {
_isLoading = false;
});
});
}

@override
void initState() {
_loadData(500);
getUser();
super.initState();
}
Expand All @@ -61,24 +73,33 @@ class _AchievementScreen extends State<AchievementScreen> {
text: '나의 기여도', fontSize: 20, fontWeight: FontWeight.w700),
centerTitle: true,
),
body: Column(
children: [
SizedBox(height: 10.h),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
UserInfo(contributionScore!, contributionPecentage!,
contributionGap, profileUrl),
badgeList(contributionScore!),
explane(),
],
),
body: _isLoading
? const Align(
alignment: Alignment.center,
child: SizedBox(
width: 50.0, // 원하는 너비
height: 50.0, // 원하는 높이
child: CircularProgressIndicator(),
),
)
: Column(
children: [
SizedBox(height: 10.h),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
UserInfo(contributionScore!, contributionPecentage!,
contributionGap, profileUrl),
badgeList(contributionScore!),
explane(),
],
),
),
),
],
),
),
],
),
),
);
}
Expand Down
22 changes: 14 additions & 8 deletions lib/screens/home/mypage/in_mypage/updateprofile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import 'dart:io';
import 'package:damyo/models/updateprofile/update_name_model.dart';
import 'package:damyo/models/updateprofile/update_profile_model.dart';
import 'package:damyo/models/userinfo/user_info_model.dart';
import 'package:damyo/screens/home/mypage/mypage_screen.dart';
import 'package:damyo/services/user_controller_service.dart';
import 'package:damyo/style.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:damyo/services/profile_update_service.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:image_picker/image_picker.dart';


String? profileImage;
final ImagePicker picker = ImagePicker();

Expand All @@ -18,8 +20,8 @@ bool _isFieldEmpty(TextEditingController controller) {
}

class UpdateprofileScreen extends StatefulWidget {
const UpdateprofileScreen({super.key});

UpdateprofileScreen({super.key, required this.update});
VoidCallback update;
@override
State<UpdateprofileScreen> createState() => _UpdateprofileState();
}
Expand All @@ -41,10 +43,10 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {

// 유저 정보를 가져오는 함수
Future<UserInfoModel?> getUserprofile() async {
UserInfoModel? user = await getUserInfo();
if (user != null) {
userInfoModel = await getUserInfo();
if (userInfoModel != null) {
setState(() {
profileImage = user.profileUrl;
profileImage = userInfoModel.profileUrl;
});
} else {
setState(() {
Expand All @@ -71,6 +73,7 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {

@override
Widget build(BuildContext context) {
FlutterSecureStorage secureStorage = const FlutterSecureStorage();
return ScreenUtilInit(
designSize: const Size(390, 755),
builder: (context, child) => Scaffold(
Expand All @@ -84,9 +87,10 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
actions: [
TextButton(
onPressed: () async {
String? token = await secureStorage.read(key: 'accessToken');
if (_profileImage != null) {
String? result2 = await putUserUpdateProfile(
UpdateProfileModel.fromMap(_profileImage));
UpdateProfileModel.fromMap(_profileImage), token!);
}

setState(() {
Expand All @@ -100,6 +104,7 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
_showErrorLog(context, '중복된 이름입니다.');
}
}
widget.update();
},
child: textFormat(
text: '완료', fontSize: 13, fontWeight: FontWeight.w500)),
Expand All @@ -122,7 +127,8 @@ class _UpdateprofileState extends State<UpdateprofileScreen> {
),
),
child: profileImage == null
? Image.asset('assets/icons/updateprofile_screen/defalut.png')
? Image.asset(
'assets/icons/updateprofile_screen/defalut.png')
: _profileImage == null
? Image.network(profileImage!)
: Image.file(
Expand Down
12 changes: 9 additions & 3 deletions lib/screens/home/mypage/mypage_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ UserInfoModel userInfoModel = UserInfoModel(
"106362899132468449802");

class _MypageScreenState extends State<MypageScreen> {

void update() {
setState(() {});
}

@override
Widget build(BuildContext context) {
return Consumer<IsLoginProvider>(
Expand Down Expand Up @@ -186,7 +191,7 @@ class _MypageScreenState extends State<MypageScreen> {
fontWeight: FontWeight.w500,
),
),
SizedBox(width: 280.w),
SizedBox(width: 250.w),
],
),
),
Expand Down Expand Up @@ -463,7 +468,8 @@ class _MypageScreenState extends State<MypageScreen> {
children: [
GestureDetector(
onTap: () {
context.push('/login');
context.push('/login',extra: update);

},
child: const Text(
'로그인/회원가입 하러 가기',
Expand Down Expand Up @@ -585,7 +591,7 @@ class _MypageScreenState extends State<MypageScreen> {
SizedBox(width: 70.w),
IconButton(
onPressed: () {
context.push('/update_profile');
context.push('/update_profile',extra: update);
},
icon: const Icon(Icons.keyboard_arrow_right)),
SizedBox(width: 10.w),
Expand Down
19 changes: 13 additions & 6 deletions lib/screens/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:damyo/services/login_service.dart';
import 'package:damyo/services/user_controller_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_naver_login/flutter_naver_login.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
Expand All @@ -14,8 +15,9 @@ import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
import 'package:provider/provider.dart';

class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
LoginScreen({super.key, required this.update});

VoidCallback update;
@override
State<LoginScreen> createState() => _LoginScreenState();
}
Expand All @@ -40,7 +42,7 @@ class _LoginScreenState extends State<LoginScreen> {
print(userInfo['token']);
await storage.write(key: 'accessToken', value: userInfo['token']);
userInfoModel = await getUserInfo();

widget.update();
context.pop();
}
}
Expand Down Expand Up @@ -68,20 +70,23 @@ class _LoginScreenState extends State<LoginScreen> {
await checkLoginState(userInfo);
}

void signInWithNaver() async {
Future<void> signInWithNaver() async {
NaverLoginResult naverUser = await FlutterNaverLogin.logIn();
NaverAccessToken naverToken = await FlutterNaverLogin.currentAccessToken;
Map<String, dynamic> userInfo;

// print(naverUser.accessToken);
print('name = ${naverUser.account.name}');
print('email = ${naverUser.account.email}');
print('id = ${naverUser.account.id}');
print(naverToken);

// await Duration(seconds: 5);
await storage.write(key: 'userID', value: naverUser.account.email);
await storage.write(key: 'sns', value: "naver");


userInfo = await login({
"token": naverToken.toString(),
"token": naverToken.accessToken,
}, "naver");
Provider.of<IsLoginProvider>(context, listen: false).login();

Expand Down Expand Up @@ -282,7 +287,9 @@ class _LoginScreenState extends State<LoginScreen> {
),
SizedBox(height: 15.h),
GestureDetector(
onTap: signInWithNaver,
onTap: ()async{
await signInWithNaver();
},
child: buildLoginButton(
text: '네이버로 계속하기',
backgroundColor: const Color(0xFF00C73C),
Expand Down
4 changes: 3 additions & 1 deletion lib/services/profile_update_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import 'dart:io';
import 'package:damyo/models/updateprofile/update_name_model.dart';
import 'package:damyo/models/updateprofile/update_profile_model.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;

Future<String?> putUserUpdateName(UpdateNameModel nameModel) async {
final baseUrl = dotenv.get('BASE_URL');
final token = dotenv.get('TEST_TOKEN');


var url = Uri.parse('$baseUrl/user/update/name?name=${nameModel.name}');
var headers = {
Expand All @@ -28,7 +30,7 @@ Future<String?> putUserUpdateName(UpdateNameModel nameModel) async {
}
}

Future<String?> putUserUpdateProfile(UpdateProfileModel profileModel) async {
Future<String?> putUserUpdateProfile(UpdateProfileModel profileModel, String token) async {
final baseUrl = dotenv.get('BASE_URL');
final token = dotenv.get('TEST_TOKEN');

Expand Down

0 comments on commit 56026b8

Please sign in to comment.