Files
login-vault-android/lib/main.dart

67 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:login_vault_app/auth_service.dart';
import 'package:login_vault_app/theme_provider.dart';
import 'package:login_vault_app/auth_screen.dart';
import 'package:login_vault_app/dashboard_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final auth = AuthService();
final theme = ThemeProvider();
final registered = await auth.isRegistered();
final email = await auth.getEmail() ?? '';
final timeout = await auth.getTimeoutMinutes();
final hasSession = await auth.hasValidSession(timeout);
final startAtDashboard = registered && email.isNotEmpty && hasSession;
runApp(
MultiProvider(
providers: [
Provider<AuthService>.value(value: auth),
ChangeNotifierProvider<ThemeProvider>.value(value: theme),
],
child: MyApp(
startAtDashboard: startAtDashboard,
auth: auth,
theme: theme,
email: email,
),
),
);
}
class MyApp extends StatelessWidget {
final bool startAtDashboard;
final AuthService auth;
final ThemeProvider theme;
final String email;
const MyApp(
{super.key,
required this.startAtDashboard,
required this.auth,
required this.theme,
required this.email});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login Vault',
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorSchemeSeed: Colors.indigo,
),
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: Colors.indigo,
),
themeMode: theme.mode,
home: startAtDashboard
? DashboardScreen(auth: auth, theme: theme, email: email)
: AuthScreen(auth: auth),
debugShowCheckedModeBanner: false,
);
}
}