Neda/Front/lib/main.dart

129 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'screens/home_screen.dart';
import 'screens/login_screen.dart';
import 'services/auth_service.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.microphone.request();
runApp(const WalkieTalkieApp());
}
class WalkieTalkieApp extends StatelessWidget {
const WalkieTalkieApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'WalkieTalkie',
theme: ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme.dark(
primary: const Color(0xFF00C853),
secondary: const Color(0xFF1DE9B6),
surface: const Color(0xFF1C1C1E),
),
scaffoldBackgroundColor: Colors.black,
useMaterial3: true,
),
home: const _Splash(),
);
}
}
class _Splash extends StatefulWidget {
const _Splash();
@override
State<_Splash> createState() => _SplashState();
}
class _SplashState extends State<_Splash> {
bool _loading = false;
Future<void> _onTap() async {
if (_loading) return;
setState(() => _loading = true);
final loggedIn = await AuthService().isLoggedIn();
if (!mounted) return;
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => loggedIn ? const HomeScreen() : const LoginScreen(),
),
);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _onTap,
child: Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 64,
height: 64,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
padding: const EdgeInsets.all(10),
child: Image.asset(
'assets/images/logo.png',
fit: BoxFit.contain,
),
),
const SizedBox(height: 14),
const Text(
'مرکز هوش مصنوعی',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
letterSpacing: 0.4,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 3),
const Text(
'و فناوری‌های نو ظهور سپاه',
style: TextStyle(
color: Color(0xFF00C853),
fontSize: 10,
letterSpacing: 0.3,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
if (_loading)
const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
color: Color(0xFF00C853),
strokeWidth: 2,
),
)
else
const Text(
'ضربه بزنید',
style: TextStyle(color: Colors.white24, fontSize: 9),
),
],
),
),
),
),
);
}
}