DevBoi

[Flutter] Naver 로그인 본문

[Mobile]/[Flutter]

[Flutter] Naver 로그인

HiSmith 2023. 11. 21. 22:18
반응형

 

1. naver developer 사이트 설정 

 

 

2. ios. info.plist

<!-- naver client_id -->
<key>naverConsumerKey</key>
<string>???</string>

<!-- naver client_secret -->
<key>naverConsumerSecret</key>
<string>?????</string>

<key>naverServiceAppName</key>
<string>????</string>

 

3. aos manifest.xml

<meta-data
  android:name="com.naver.sdk.clientId"
  android:value="???" />
<meta-data
  android:name="com.naver.sdk.clientSecret"
  android:value="???" />
<meta-data
  android:name="com.naver.sdk.clientName"
  android:value="???" />

 

 

4. 디펜던시 추가 (Pubspec.yaml)

flutter_naver_login: ^1.6.0

 

 

5. 네이버 로그인 관련 소스

import 'package:flutter_naver_login/flutter_naver_login.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:myvalue/util/chat/widget/message.dart';
import 'package:myvalue/view/sociallogin/social_login.dart';
import 'package:myvalue/view/util/provider-util.dart';

class NaverLogin implements SocialLogin{
  @override
  Future<bool> login() async{
  final NaverLoginResult result = await FlutterNaverLogin.logIn();

  if(result != null){
    print(result);
    // userProvider.setUserId(googleUser.id);
    // userProvider.setName(googleUser.displayName!);
    // userProvider.setEmail(googleUser.email);
    return true;
  }
  else{
    return false;
  }
  }

  @override
  Future<bool> logout() {

    throw UnimplementedError();
  }
}

import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
import 'package:myvalue/view/sociallogin/kakao/userprofile/kakao_profile.dart';
import '../social_login.dart';

class NaverViewModel{
  final SocialLogin _socialLogin;
  bool isLogined = false;
  User? user;
  NaverViewModel(this._socialLogin){
  }

  Future register() async{
    isLogined = await _socialLogin.login();
    if(isLogined){
      return true;
    }
    return false;
  }

  Future logout() async{
    await _socialLogin.logout();
    isLogined = false;
    user = null;
  }
}

 

 

이처럼 진행하면, 로그인 및 가입이 가능하다.

반응형