Fix white screen after login: pushReplacement to DashboardScreen; main decides home by email presence; add missing imports

This commit is contained in:
cania
2026-08-12 12:38:44 +02:00
parent 4c681914f5
commit 761d746a83
3 changed files with 24 additions and 11 deletions

View File

@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:provider/provider.dart';
import 'package:login_vault_app/auth_service.dart';
import 'package:login_vault_app/dashboard_screen.dart';
import 'package:login_vault_app/theme_provider.dart';
/// First-launch screen: register with email+password, or with Google.
class AuthScreen extends StatefulWidget {
@@ -18,6 +21,19 @@ class _AuthScreenState extends State<AuthScreen> {
bool _busy = false;
String? _error;
void _goToDashboard(String email) {
if (!mounted) return;
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => DashboardScreen(
auth: widget.auth,
theme: Provider.of<ThemeProvider>(context, listen: false),
email: email,
),
),
);
}
Future<void> _submitEmail() async {
setState(() => _busy = true);
final email = _emailCtrl.text.trim();
@@ -36,12 +52,11 @@ class _AuthScreenState extends State<AuthScreen> {
} else if (!ok) {
setState(() => _error = 'Password aplikasi salah');
} else {
// success -> pop true
if (mounted) Navigator.pop(context, true);
_goToDashboard(email);
}
} else {
await widget.auth.registerWithEmail(email, pass);
if (mounted) Navigator.pop(context, true);
_goToDashboard(email);
}
} catch (e) {
setState(() => _error = e.toString());
@@ -57,7 +72,7 @@ class _AuthScreenState extends State<AuthScreen> {
final account = await gs.signIn();
if (account?.email != null) {
await widget.auth.registerWithGoogle(account!.email);
if (mounted) Navigator.pop(context, true);
_goToDashboard(account.email);
} else {
setState(() => _error = 'Google sign-in dibatalkan');
}