92 lines
2.6 KiB
Dart
92 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../logic/auth_provider.dart';
|
|
import 'login_screen.dart';
|
|
import 'contacts_screen.dart';
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
const SplashScreen({super.key});
|
|
|
|
@override
|
|
State<SplashScreen> createState() => _SplashScreenState();
|
|
}
|
|
|
|
class _SplashScreenState extends State<SplashScreen> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_initializeApp();
|
|
}
|
|
|
|
Future<void> _initializeApp() async {
|
|
// 1. Искусственная задержка в 2 секунды
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
|
|
if (!mounted) return;
|
|
|
|
// 2. Пытаемся выполнить автологин
|
|
final authProvider = context.read<AuthProvider>();
|
|
final isLoggedIn = await authProvider.tryAutoLogin();
|
|
|
|
if (!mounted) return;
|
|
|
|
// 3. Навигация в зависимости от результата
|
|
if (isLoggedIn) {
|
|
await authProvider.initRealtime(); // Запускаем сокет сразу
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const ContactsScreen()),
|
|
);
|
|
} else {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Spacer(),
|
|
Icon(
|
|
Icons.messenger_outline,
|
|
size: 80,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
const SizedBox(height: 24),
|
|
Text(
|
|
"Chepuhagram",
|
|
style: TextStyle(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
fontSize: 32,
|
|
fontWeight: FontWeight.bold,
|
|
letterSpacing: 1.2,
|
|
),
|
|
),
|
|
const SizedBox(height: 40),
|
|
// Мягкий индикатор загрузки снизу
|
|
CircularProgressIndicator(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
const Spacer(),
|
|
Text(
|
|
'Made by ArturKarasevich',
|
|
style: TextStyle(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
const SizedBox(height: 80),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|