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');
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeProvider>(context);
|
||||
final auth = Provider.of<AuthService>(context, listen: false);
|
||||
return MaterialApp(
|
||||
title: 'Login Vault',
|
||||
theme: ThemeData(
|
||||
@@ -43,13 +44,10 @@ class MyApp extends StatelessWidget {
|
||||
colorSchemeSeed: Colors.indigo,
|
||||
),
|
||||
themeMode: theme.mode,
|
||||
home: registered
|
||||
? DashboardScreen(
|
||||
auth: context.read<AuthService>(),
|
||||
theme: theme,
|
||||
email: email,
|
||||
)
|
||||
: AuthScreen(auth: context.read<AuthService>()),
|
||||
// decide home: if registered AND email known -> Dashboard, else Auth.
|
||||
home: (registered && email.isNotEmpty)
|
||||
? DashboardScreen(auth: auth, theme: theme, email: email)
|
||||
: AuthScreen(auth: auth),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user