import 'package:flutter/material.dart'; import 'src/app_state.dart'; import 'src/models.dart'; const _bg = Color(0xFF05080B); const _panel = Color(0xFF0C151D); const _line = Color(0xFF1E303A); const _cyan = Color(0xFF8FE3F5); const _green = Color(0xFF8DFFAD); const _muted = Color(0xFF91AAB7); const _red = Color(0xFFFF8F9F); void main() async { WidgetsFlutterBinding.ensureInitialized(); final state = AppState(); await state.initialize(); runApp(LdFdpiApp(state: state)); } class LdFdpiApp extends StatelessWidget { final AppState state; const LdFdpiApp({super.key, required this.state}); @override Widget build(BuildContext context) { final scheme = ColorScheme.fromSeed( seedColor: _cyan, brightness: Brightness.dark, ).copyWith( surface: _panel, primary: _cyan, secondary: _green, error: _red, ); return MaterialApp( title: 'LD FDPI', debugShowCheckedModeBanner: false, theme: ThemeData( useMaterial3: true, brightness: Brightness.dark, colorScheme: scheme, scaffoldBackgroundColor: _bg, fontFamily: 'sans-serif', textTheme: const TextTheme( headlineLarge: TextStyle(fontWeight: FontWeight.w900, letterSpacing: -1.4), headlineMedium: TextStyle(fontWeight: FontWeight.w800, letterSpacing: -0.8), titleMedium: TextStyle(fontWeight: FontWeight.w700), bodyMedium: TextStyle(color: _muted, height: 1.45), bodySmall: TextStyle(color: _muted, height: 1.4), ), ), home: HomeScreen(state: state), ); } } class HomeScreen extends StatelessWidget { final AppState state; const HomeScreen({super.key, required this.state}); @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ const _Aurora(), SafeArea( child: ListenableBuilder( listenable: state, builder: (context, _) { return ListView( padding: const EdgeInsets.fromLTRB(20, 18, 20, 28), children: [ _Header(onSettings: () => _openSettings(context)), const SizedBox(height: 28), _StatusOrb(state: state), const SizedBox(height: 18), Center(child: _statusLabel(state)), const SizedBox(height: 6), Center( child: Text( state.connecting ? 'El sıkışma bekleniyor...' : state.connected ? 'Trafik tünelden geçiyor' : 'Bağlanmaya hazır', style: const TextStyle(color: _muted, fontSize: 12), ), ), const SizedBox(height: 24), _ConnectButton(state: state), if (state.error != null) ...[ const SizedBox(height: 12), _ErrorBox(message: state.error!), ], const SizedBox(height: 22), _InfoGrid(state: state), const SizedBox(height: 12), _ActivationCard(state: state), const SizedBox(height: 12), _SecurityCard(state: state), const SizedBox(height: 12), _Footer(), ], ); }, ), ), ], ), ); } void _openSettings(BuildContext context) { Navigator.of(context).push( MaterialPageRoute(builder: (_) => SettingsScreen(state: state)), ); } } class _Header extends StatelessWidget { final VoidCallback onSettings; const _Header({required this.onSettings}); @override Widget build(BuildContext context) { return Row( children: [ Container( width: 38, height: 38, decoration: BoxDecoration( borderRadius: BorderRadius.circular(11), border: Border.all(color: _cyan.withOpacity(0.35)), color: _cyan.withOpacity(0.08), ), child: const Icon(Icons.shield_outlined, color: _cyan, size: 21), ), const SizedBox(width: 11), const Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('LD FDPI', style: TextStyle(fontWeight: FontWeight.w900, fontSize: 16, letterSpacing: -0.3)), Text('MOBILE TUNNEL', style: TextStyle(color: _muted, fontSize: 9, letterSpacing: 2)), ], ), ), IconButton( onPressed: onSettings, icon: const Icon(Icons.tune_rounded, color: _muted), tooltip: 'Ayarlar', ), ], ); } } class _StatusOrb extends StatelessWidget { final AppState state; const _StatusOrb({required this.state}); @override Widget build(BuildContext context) { final connected = state.connected; final busy = state.connecting; final color = connected ? _green : busy ? const Color(0xFFFFD27A) : _cyan; return Center( child: AnimatedContainer( duration: const Duration(milliseconds: 450), curve: Curves.easeOutCubic, width: 196, height: 196, decoration: BoxDecoration( shape: BoxShape.circle, gradient: RadialGradient( colors: [ color.withOpacity(0.18), color.withOpacity(0.04), Colors.transparent, ], stops: const [0.0, 0.55, 1.0], ), border: Border.all(color: color.withOpacity(0.35), width: 1), boxShadow: [ BoxShadow(color: color.withOpacity(0.14), blurRadius: 50, spreadRadius: 8), ], ), child: Center( child: AnimatedContainer( duration: const Duration(milliseconds: 350), width: 116, height: 116, decoration: BoxDecoration( shape: BoxShape.circle, color: _panel.withOpacity(0.9), border: Border.all(color: color.withOpacity(0.45)), ), child: busy ? Padding( padding: const EdgeInsets.all(40), child: CircularProgressIndicator(strokeWidth: 2, color: color), ) : Icon( connected ? Icons.shield_rounded : Icons.shield_outlined, color: color, size: 46, ), ), ), ), ); } } Widget _statusLabel(AppState state) { final text = state.connected ? 'BAĞLI' : state.connecting ? 'BAĞLANIYOR' : state.status.state == TunnelState.error ? 'HATA' : 'BAĞLI DEĞİL'; final color = state.connected ? _green : state.connecting ? const Color(0xFFFFD27A) : _muted; return Text( text, style: TextStyle(color: color, fontSize: 11, fontWeight: FontWeight.w800, letterSpacing: 3), ); } class _ConnectButton extends StatelessWidget { final AppState state; const _ConnectButton({required this.state}); @override Widget build(BuildContext context) { final disabled = state.busy; if (state.connected) { return SizedBox( height: 54, child: FilledButton.icon( onPressed: disabled ? null : state.disconnect, style: FilledButton.styleFrom( backgroundColor: _panel, foregroundColor: _red, side: BorderSide(color: _red.withOpacity(0.35)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)), ), icon: const Icon(Icons.power_settings_new_rounded), label: const Text('BAĞLANTIYI KES', style: TextStyle(fontWeight: FontWeight.w800, letterSpacing: 0.6)), ), ); } return SizedBox( height: 54, child: FilledButton.icon( onPressed: disabled ? null : state.connect, style: FilledButton.styleFrom( backgroundColor: _cyan, foregroundColor: _bg, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)), ), icon: const Icon(Icons.bolt_rounded), label: const Text('BAĞLAN', style: TextStyle(fontWeight: FontWeight.w900, letterSpacing: 0.8)), ), ); } } class _InfoGrid extends StatelessWidget { final AppState state; const _InfoGrid({required this.state}); @override Widget build(BuildContext context) { return Row( children: [ Expanded(child: _InfoTile(label: 'ATANAN IP', value: state.address, icon: Icons.lan_outlined)), const SizedBox(width: 10), Expanded(child: _InfoTile(label: 'ÇIKIŞ', value: state.endpoint, icon: Icons.public_rounded)), ], ); } } class _InfoTile extends StatelessWidget { final String label; final String value; final IconData icon; const _InfoTile({required this.label, required this.value, required this.icon}); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(14), decoration: BoxDecoration( color: _panel, borderRadius: BorderRadius.circular(14), border: Border.all(color: _line), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon(icon, size: 13, color: _cyan), const SizedBox(width: 6), Text(label, style: const TextStyle(color: _muted, fontSize: 8, letterSpacing: 1.3)), ], ), const SizedBox(height: 8), Text( value, maxLines: 1, overflow: TextOverflow.ellipsis, style: const TextStyle(fontFamily: 'monospace', fontSize: 11, fontWeight: FontWeight.w700), ), ], ), ); } } class _ActivationCard extends StatelessWidget { final AppState state; const _ActivationCard({required this.state}); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: _panel, borderRadius: BorderRadius.circular(16), border: Border.all(color: _line), ), child: Row( children: [ const Icon(Icons.key_rounded, color: _cyan, size: 20), const SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(state.hasConfig ? 'Cihaz kayıtlı' : 'Etkinleştirme gerekli', style: const TextStyle(fontWeight: FontWeight.w800, fontSize: 12)), const SizedBox(height: 3), Text( state.hasConfig ? 'Kimlik bu cihazda şifreli saklanıyor.' : 'Tek kullanımlık kodunu gir, tüneli aç.', style: const TextStyle(color: _muted, fontSize: 10.5), ), ], ), ), TextButton( onPressed: () => _showEnrollment(context), child: Text(state.hasConfig ? 'YENİLE' : 'KOD GİR', style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w800)), ), ], ), ); } void _showEnrollment(BuildContext context) { showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: _panel, shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(22))), builder: (sheetContext) => Padding( padding: EdgeInsets.only(bottom: MediaQuery.of(sheetContext).viewInsets.bottom), child: _EnrollmentSheet(state: state), ), ); } } class _EnrollmentSheet extends StatefulWidget { final AppState state; const _EnrollmentSheet({required this.state}); @override State<_EnrollmentSheet> createState() => _EnrollmentSheetState(); } class _EnrollmentSheetState extends State<_EnrollmentSheet> { final _controller = TextEditingController(); @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.fromLTRB(20, 18, 20, 24), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('Etkinleştirme kodu', style: TextStyle(fontSize: 20, fontWeight: FontWeight.w900)), const SizedBox(height: 6), const Text('Kod tek kullanımlık ve bu cihaza bağlanır.', style: TextStyle(color: _muted, fontSize: 12)), const SizedBox(height: 18), TextField( controller: _controller, autofocus: true, textCapitalization: TextCapitalization.characters, style: const TextStyle(fontFamily: 'monospace', letterSpacing: 1), decoration: InputDecoration( hintText: 'LDFDPI-XXXX-XXXX-XXXX', filled: true, fillColor: _bg, border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: _line)), enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: _line)), focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: _cyan)), ), onSubmitted: (_) => _submit(), ), if (widget.state.error != null) ...[ const SizedBox(height: 10), Text(widget.state.error!, style: const TextStyle(color: _red, fontSize: 11)), ], const SizedBox(height: 16), SizedBox( width: double.infinity, height: 48, child: ListenableBuilder( listenable: widget.state, builder: (context, _) { return FilledButton( onPressed: widget.state.busy ? null : _submit, style: FilledButton.styleFrom(backgroundColor: _cyan, foregroundColor: _bg, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))), child: widget.state.busy ? const SizedBox(width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2, color: _bg)) : const Text('KAYDI TAMAMLA', style: TextStyle(fontWeight: FontWeight.w900, letterSpacing: 0.6)), ); }, ), ), ], ), ); } Future _submit() async { await widget.state.enroll(_controller.text); if (widget.state.hasConfig && mounted) Navigator.of(context).pop(); } } class _SecurityCard extends StatelessWidget { final AppState state; const _SecurityCard({required this.state}); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: _panel, borderRadius: BorderRadius.circular(16), border: Border.all(color: _line), ), child: Column( children: [ _SecurityRow(icon: Icons.dns_outlined, label: 'DNS', value: state.config?.dns.join(', ') ?? '1.1.1.1'), const SizedBox(height: 10), _SecurityRow(icon: Icons.speed_rounded, label: 'GECİKME', value: state.pingMs == null ? '—' : '${state.pingMs} ms'), const SizedBox(height: 10), _SecurityRow(icon: Icons.block_rounded, label: 'SIZINTI', value: state.connected ? 'KORUMALI' : 'PASİF'), ], ), ); } } class _SecurityRow extends StatelessWidget { final IconData icon; final String label; final String value; const _SecurityRow({required this.icon, required this.label, required this.value}); @override Widget build(BuildContext context) { return Row( children: [ Icon(icon, size: 15, color: _cyan), const SizedBox(width: 9), Text(label, style: const TextStyle(color: _muted, fontSize: 9, letterSpacing: 1.1)), const Spacer(), Flexible( child: Text( value, textAlign: TextAlign.right, overflow: TextOverflow.ellipsis, style: const TextStyle(fontFamily: 'monospace', fontSize: 10.5, color: Color(0xFFD8ECF2)), ), ), ], ); } } class _ErrorBox extends StatelessWidget { final String message; const _ErrorBox({required this.message}); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: _red.withOpacity(0.07), border: Border.all(color: _red.withOpacity(0.3)), borderRadius: BorderRadius.circular(11), ), child: Text(message, style: const TextStyle(color: _red, fontSize: 11)), ); } } class _Footer extends StatelessWidget { @override Widget build(BuildContext context) { return const Padding( padding: EdgeInsets.only(top: 8), child: Text( 'LD FDPI v0.1.0 · Android VpnService · AES-GCM secure storage', textAlign: TextAlign.center, style: TextStyle(color: Color(0xFF536B77), fontSize: 9), ), ); } } class _Aurora extends StatelessWidget { const _Aurora(); @override Widget build(BuildContext context) { return IgnorePointer( child: Stack( children: [ Positioned( top: -180, right: -120, child: Container( width: 420, height: 420, decoration: BoxDecoration( shape: BoxShape.circle, gradient: RadialGradient(colors: [_cyan.withOpacity(0.13), Colors.transparent]), ), ), ), Positioned( bottom: -220, left: -160, child: Container( width: 460, height: 460, decoration: BoxDecoration( shape: BoxShape.circle, gradient: RadialGradient(colors: [_green.withOpacity(0.06), Colors.transparent]), ), ), ), ], ), ); } } class SettingsScreen extends StatelessWidget { final AppState state; const SettingsScreen({super.key, required this.state}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: _bg, title: const Text('Ayarlar', style: TextStyle(fontWeight: FontWeight.w800)), leading: IconButton(onPressed: () => Navigator.pop(context), icon: const Icon(Icons.arrow_back_rounded)), ), body: ListenableBuilder( listenable: state, builder: (context, _) => ListView( padding: const EdgeInsets.all(20), children: [ _SettingsCard( title: 'Tünel', rows: [ _SettingsRow('Sunucu', state.config?.endpoint ?? '—'), _SettingsRow('Adres', state.config?.address ?? '—'), _SettingsRow('DNS', state.config?.dns.join(', ') ?? '1.1.1.1'), _SettingsRow('AmneziaWG', state.config == null ? '—' : 'Jc ${state.config!.awg.jc} · S1 ${state.config!.awg.s1}'), ], ), const SizedBox(height: 12), _SettingsCard( title: 'Sızıntı koruması', rows: const [ _SettingsRow('VPN', 'Android VpnService'), _SettingsRow('DNS', 'Tünel içi 1.1.1.1 / 1.0.0.1'), _SettingsRow('Kill-switch', 'Always-on VPN + Block without VPN'), ], ), const SizedBox(height: 10), FilledButton.tonalIcon( onPressed: state.openVpnSettings, icon: const Icon(Icons.open_in_new_rounded, size: 17), label: const Text('Android VPN ayarlarını aç'), ), const SizedBox(height: 8), const Text( 'Android, “Always-on VPN” ve “Block connections without VPN” ayarlarını uygulama adına açmaya izin vermez. Ayarlar ekranından kullanıcı tarafından açılmalıdır.', style: TextStyle(color: _muted, fontSize: 10.5, height: 1.45), ), const SizedBox(height: 22), const _SettingsCard( title: 'Uygulama', rows: [ _SettingsRow('Sürüm', '0.1.0'), _SettingsRow('Depolama', 'EncryptedSharedPreferences'), _SettingsRow('Kimlik', 'X25519 · cihaz başına'), ], ), ], ), ), ); } } class _SettingsCard extends StatelessWidget { final String title; final List rows; const _SettingsCard({required this.title, required this.rows}); @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration(color: _panel, borderRadius: BorderRadius.circular(16), border: Border.all(color: _line)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(title.toUpperCase(), style: const TextStyle(color: _muted, fontSize: 9, letterSpacing: 1.4, fontWeight: FontWeight.w700)), const SizedBox(height: 10), ...rows, ], ), ); } } class _SettingsRow extends StatelessWidget { final String label; final String value; const _SettingsRow(this.label, this.value); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(vertical: 5), child: Row( children: [ Expanded(child: Text(label, style: const TextStyle(fontSize: 11.5, color: _muted))), Flexible( child: Text( value, textAlign: TextAlign.right, overflow: TextOverflow.ellipsis, style: const TextStyle(fontFamily: 'monospace', fontSize: 10.5, color: Color(0xFFD8ECF2)), ), ), ], ), ); } }