import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'screens/login_screen.dart'; import 'screens/phone_screen.dart'; class TwpSoftphoneApp extends StatefulWidget { const TwpSoftphoneApp({super.key}); @override State createState() => _TwpSoftphoneAppState(); } class _TwpSoftphoneAppState extends State { static const _storage = FlutterSecureStorage(); String? _serverUrl; bool _loading = true; @override void initState() { super.initState(); _checkSavedSession(); } Future _checkSavedSession() async { final url = await _storage.read(key: 'server_url'); if (mounted) { setState(() { _serverUrl = url; _loading = false; }); } } void _onLoginSuccess(String serverUrl) { setState(() { _serverUrl = serverUrl; }); } void _onLogout() async { await _storage.delete(key: 'server_url'); if (mounted) { setState(() { _serverUrl = null; }); } } void _onSessionExpired() { // Server URL is still saved, but session cookie is gone. // Show login screen but keep the server URL pre-filled. if (mounted) { setState(() { _serverUrl = null; }); } } @override Widget build(BuildContext context) { return MaterialApp( title: 'TWP Softphone', debugShowCheckedModeBanner: false, theme: ThemeData( colorSchemeSeed: Colors.blue, useMaterial3: true, brightness: Brightness.light, ), darkTheme: ThemeData( colorSchemeSeed: Colors.blue, useMaterial3: true, brightness: Brightness.dark, ), home: _loading ? const Scaffold( body: Center(child: CircularProgressIndicator()), ) : _serverUrl != null ? PhoneScreen( serverUrl: _serverUrl!, onLogout: _onLogout, onSessionExpired: _onSessionExpired, ) : LoginScreen(onLoginSuccess: _onLoginSuccess), ); } }