Support Google Services based sign-in config

This commit is contained in:
zsolt 2026-08-13 01:52:31 +02:00
parent 3de2fa714f
commit ac9c9de753
3 changed files with 30 additions and 18 deletions

View File

@ -4,6 +4,10 @@ plugins {
id("dev.flutter.flutter-gradle-plugin")
}
if (file("google-services.json").exists()) {
apply(plugin = "com.google.gms.google-services")
}
android {
namespace = "hu.otthonnaptar.otthon_naptar"
compileSdk = flutter.compileSdkVersion

View File

@ -21,6 +21,7 @@ plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "9.0.1" apply false
id("org.jetbrains.kotlin.android") version "2.3.20" apply false
id("com.google.gms.google-services") version "4.4.4" apply false
}
include(":app")

View File

@ -30,7 +30,7 @@ class _AccountsPageState extends State<AccountsPage> {
final googleSignIn = GoogleSignIn.instance;
List<GoogleCalendarInfo> googleCalendars = [];
GoogleSignInAccount? signedInAccount;
String runtimeServerClientId = googleCalendarServerClientId;
String? runtimeServerClientId;
bool initialized = false;
bool loadingCalendars = false;
bool syncing = false;
@ -53,16 +53,7 @@ class _AccountsPageState extends State<AccountsPage> {
final configuredClientId = await _loadGoogleServerClientId();
if (!mounted) return;
if (configuredClientId == null || configuredClientId.trim().isEmpty) {
setState(() {
loadingCalendars = false;
statusMessage =
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve. A csal\u00e1dtagoknak nem kell client ID-t megadniuk; a JARVIS admin fel\u00fcleten kell egyszer be\u00e1ll\u00edtani a Google Calendar OAuth azonos\u00edt\u00f3t.';
});
return;
}
runtimeServerClientId = configuredClientId.trim();
runtimeServerClientId = configuredClientId?.trim();
await _initializeGoogle();
}
@ -121,7 +112,10 @@ class _AccountsPageState extends State<AccountsPage> {
if (!mounted) return;
setState(() {
loadingCalendars = false;
statusMessage = 'Google inicializ\u00e1l\u00e1s nem siker\u00fclt: $error';
statusMessage = _friendlyGoogleError(
'Google inicializ\u00e1l\u00e1s nem siker\u00fclt',
error,
);
});
}
}
@ -163,17 +157,30 @@ class _AccountsPageState extends State<AccountsPage> {
if (!mounted) return;
setState(() {
loadingCalendars = false;
statusMessage = 'Google bejelentkez\u00e9s nem siker\u00fclt: $error';
statusMessage = _friendlyGoogleError(
'Google bejelentkez\u00e9s nem siker\u00fclt',
error,
);
});
}
}
String _friendlyGoogleError(String prefix, Object error) {
final raw = error.toString();
if (raw.contains('serverClientId must be provided') ||
raw.contains('CredentialManager requires a serverClientId')) {
return '$prefix: hi\u00e1nyzik az app Google konfigur\u00e1ci\u00f3ja. '
'A bel\u00e9p\u00e9si ablakos m\u0171k\u00f6d\u00e9shez tedd be az android/app/google-services.json f\u00e1jlt, '
'amely tartalmaz Web application OAuth client ID-t, majd buildeld \u00fajra az APK-t.';
}
return '$prefix: $raw';
}
Future<void> _ensureGoogleInitialized() async {
final clientId = runtimeServerClientId.trim();
if (clientId.isEmpty) {
throw Exception(
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve.',
);
final clientId = runtimeServerClientId;
if (clientId == null || clientId.isEmpty) {
await googleSignIn.initialize();
return;
}
await googleSignIn.initialize(