2026-04-26 12:00:14 +10:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2026-04-26 15:49:52 +10:00
|
|
|
|
|
|
|
|
import 'core/providers/biometric_provider.dart';
|
2026-04-26 14:42:39 +10:00
|
|
|
import 'core/providers/model_download_provider.dart';
|
2026-04-26 15:49:52 +10:00
|
|
|
import 'core/providers/settings_provider.dart';
|
|
|
|
|
import 'core/providers/theme_provider.dart';
|
2026-04-26 14:42:39 +10:00
|
|
|
import 'features/model_download/model_download_screen.dart';
|
2026-04-26 14:21:12 +10:00
|
|
|
import 'shell.dart';
|
2026-04-26 12:00:14 +10:00
|
|
|
|
|
|
|
|
class App extends ConsumerWidget {
|
|
|
|
|
const App({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2026-04-26 15:14:17 +10:00
|
|
|
final skipped = ref.watch(modelSkippedProvider);
|
2026-04-26 14:42:39 +10:00
|
|
|
final modelPresentAsync = ref.watch(modelPresentProvider);
|
2026-04-26 15:49:52 +10:00
|
|
|
final themeModeAsync = ref.watch(themeModeProvider);
|
|
|
|
|
final biometricEnabled =
|
|
|
|
|
ref.watch(settingProvider(SettingsKeys.biometricEnabled));
|
|
|
|
|
final biometricUnlocked = ref.watch(biometricUnlockedProvider);
|
|
|
|
|
|
|
|
|
|
final themeMode = themeModeAsync.value ?? ThemeMode.system;
|
|
|
|
|
|
|
|
|
|
Widget mainContent() {
|
|
|
|
|
if (biometricEnabled.value == 'true' && !biometricUnlocked) {
|
|
|
|
|
return const _BiometricLockScreen();
|
|
|
|
|
}
|
|
|
|
|
return const AppShell();
|
|
|
|
|
}
|
2026-04-26 12:00:14 +10:00
|
|
|
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'DailyYou',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
theme: _lightTheme(),
|
|
|
|
|
darkTheme: _darkTheme(),
|
2026-04-26 15:49:52 +10:00
|
|
|
themeMode: themeMode,
|
2026-04-26 15:14:17 +10:00
|
|
|
home: skipped
|
2026-04-26 15:49:52 +10:00
|
|
|
? mainContent()
|
2026-04-26 15:14:17 +10:00
|
|
|
: modelPresentAsync.when(
|
|
|
|
|
data: (present) =>
|
2026-04-26 15:49:52 +10:00
|
|
|
present ? mainContent() : const ModelDownloadScreen(),
|
2026-04-26 15:14:17 +10:00
|
|
|
loading: () => const Scaffold(
|
|
|
|
|
body: Center(child: CircularProgressIndicator()),
|
|
|
|
|
),
|
|
|
|
|
error: (_, __) => const ModelDownloadScreen(),
|
|
|
|
|
),
|
2026-04-26 12:00:14 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThemeData _lightTheme() => ThemeData(
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
|
seedColor: const Color(0xFF6B8CFF),
|
|
|
|
|
brightness: Brightness.light,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ThemeData _darkTheme() => ThemeData(
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
|
seedColor: const Color(0xFF6B8CFF),
|
|
|
|
|
brightness: Brightness.dark,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-26 15:49:52 +10:00
|
|
|
|
|
|
|
|
class _BiometricLockScreen extends ConsumerStatefulWidget {
|
|
|
|
|
const _BiometricLockScreen();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
ConsumerState<_BiometricLockScreen> createState() =>
|
|
|
|
|
_BiometricLockScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _BiometricLockScreenState extends ConsumerState<_BiometricLockScreen> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
ref.read(biometricUnlockedProvider.notifier).tryUnlock();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
|
return Scaffold(
|
|
|
|
|
body: Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(Icons.lock_outline, size: 64, color: cs.primary),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
Text('DailyYou is locked',
|
|
|
|
|
style: Theme.of(context).textTheme.titleLarge),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
FilledButton.icon(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
ref.read(biometricUnlockedProvider.notifier).tryUnlock(),
|
|
|
|
|
icon: const Icon(Icons.fingerprint),
|
|
|
|
|
label: const Text('Unlock'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|