Fix white screen after login: pushReplacement to DashboardScreen; main decides home by email presence; add missing imports
This commit is contained in:
BIN
app-release.apk
Normal file
BIN
app-release.apk
Normal file
Binary file not shown.
@@ -1,6 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.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/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.
|
/// First-launch screen: register with email+password, or with Google.
|
||||||
class AuthScreen extends StatefulWidget {
|
class AuthScreen extends StatefulWidget {
|
||||||
@@ -18,6 +21,19 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
bool _busy = false;
|
bool _busy = false;
|
||||||
String? _error;
|
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 {
|
Future<void> _submitEmail() async {
|
||||||
setState(() => _busy = true);
|
setState(() => _busy = true);
|
||||||
final email = _emailCtrl.text.trim();
|
final email = _emailCtrl.text.trim();
|
||||||
@@ -36,12 +52,11 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
} else if (!ok) {
|
} else if (!ok) {
|
||||||
setState(() => _error = 'Password aplikasi salah');
|
setState(() => _error = 'Password aplikasi salah');
|
||||||
} else {
|
} else {
|
||||||
// success -> pop true
|
_goToDashboard(email);
|
||||||
if (mounted) Navigator.pop(context, true);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await widget.auth.registerWithEmail(email, pass);
|
await widget.auth.registerWithEmail(email, pass);
|
||||||
if (mounted) Navigator.pop(context, true);
|
_goToDashboard(email);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() => _error = e.toString());
|
setState(() => _error = e.toString());
|
||||||
@@ -57,7 +72,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
final account = await gs.signIn();
|
final account = await gs.signIn();
|
||||||
if (account?.email != null) {
|
if (account?.email != null) {
|
||||||
await widget.auth.registerWithGoogle(account!.email);
|
await widget.auth.registerWithGoogle(account!.email);
|
||||||
if (mounted) Navigator.pop(context, true);
|
_goToDashboard(account.email);
|
||||||
} else {
|
} else {
|
||||||
setState(() => _error = 'Google sign-in dibatalkan');
|
setState(() => _error = 'Google sign-in dibatalkan');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class MyApp extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Provider.of<ThemeProvider>(context);
|
final theme = Provider.of<ThemeProvider>(context);
|
||||||
|
final auth = Provider.of<AuthService>(context, listen: false);
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Login Vault',
|
title: 'Login Vault',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
@@ -43,13 +44,10 @@ class MyApp extends StatelessWidget {
|
|||||||
colorSchemeSeed: Colors.indigo,
|
colorSchemeSeed: Colors.indigo,
|
||||||
),
|
),
|
||||||
themeMode: theme.mode,
|
themeMode: theme.mode,
|
||||||
home: registered
|
// decide home: if registered AND email known -> Dashboard, else Auth.
|
||||||
? DashboardScreen(
|
home: (registered && email.isNotEmpty)
|
||||||
auth: context.read<AuthService>(),
|
? DashboardScreen(auth: auth, theme: theme, email: email)
|
||||||
theme: theme,
|
: AuthScreen(auth: auth),
|
||||||
email: email,
|
|
||||||
)
|
|
||||||
: AuthScreen(auth: context.read<AuthService>()),
|
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user