flutter create login_test
# keytool 명령어는 자바가 설치되어있어야 합니다.
keytool -genkey -v -keystore debug.keystore -alias debug -keyalg RSA -keysize 2048 -validity 10000
gradlew.bat signingReport
android {
...
signingConfigs {
getByName("debug") {
storeFile = file("debug.keystore")
storePassword = "000000"
keyAlias = "debug"
keyPassword = "000000"
}
...
}
buildTypes {
debug {
signingConfig = signingConfigs.getByName("debug")
}
...
}
...
}

// android\app\build.gradle.kts
...
defaultConfig {
applicationId = "com.example.login_test" // 패키지 이름
minSdk = 23
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
...
INFO: 안드로이드용 클라이언트를 등록하지 않으면 로그인 자체가 안되고, 웹용 클라이언트를 등록하지 않으면 id_token을 가져오지 못합니다.
IMPORTANT: 안드로이드용 클라이언트 ID 아님
...
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: ['openid', 'email', 'profile'],
serverClientId:
'<웹용 클라이언트 ID>',
);
...
lib/main.dart
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const OnBoarding(),
);
}
}
class OnBoarding extends StatefulWidget {
const OnBoarding({super.key});
State<OnBoarding> createState() => _OnBoardingState();
}
class _OnBoardingState extends State<OnBoarding> {
void initState() {
super.initState();
}
Future<void> _signIn() async {
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: ['openid', 'email', 'profile'],
serverClientId:
'<웹용 클라이언트 ID>',
);
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
final GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
print("email: ${googleUser?.email}");
print("accessToken: ${googleAuth?.accessToken}");
print("idToken: ${googleAuth?.idToken}");
}
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(onPressed: _signIn, child: Text('Sign In')),
),
);
}
}
# terminal1: 구동
flutter run
#terminal2: 로그 (해당 터미널에서 id_token 확인)
flutter logs