Fix white screen after login: pushReplacement to DashboardScreen; main decides home by email presence; add missing imports
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user