UI resposiveness fix on mobile

This commit is contained in:
2024-11-11 00:07:32 +01:00
parent c7233daec7
commit a857648c48

View File

@@ -44,7 +44,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
final FocusNode _frequencyFocusNode = FocusNode(); final FocusNode _frequencyFocusNode = FocusNode();
final FocusNode _squawkFocusNode = FocusNode(); final FocusNode _squawkFocusNode = FocusNode();
// Neue Variablen
bool _saveSimbriefId = false; bool _saveSimbriefId = false;
static const String _simbriefIdKey = 'simbrief_id'; static const String _simbriefIdKey = 'simbrief_id';
@@ -54,7 +53,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
_loadSavedSimbriefId(); _loadSavedSimbriefId();
} }
// Methode zum Laden der gespeicherten ID
Future<void> _loadSavedSimbriefId() async { Future<void> _loadSavedSimbriefId() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
final savedId = prefs.getString(_simbriefIdKey); final savedId = prefs.getString(_simbriefIdKey);
@@ -66,7 +64,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
} }
} }
// Methode zum Speichern der ID
Future<void> _saveSimbriefIdToPrefs() async { Future<void> _saveSimbriefIdToPrefs() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
if (_saveSimbriefId) { if (_saveSimbriefId) {
@@ -100,7 +97,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
Uri.parse('https://www.simbrief.com/api/xml.fetcher.php?userid=${_simbriefIdController.text}&json=1'), Uri.parse('https://www.simbrief.com/api/xml.fetcher.php?userid=${_simbriefIdController.text}&json=1'),
); );
// Prüfe ob Widget noch mounted ist
if (!mounted) return; if (!mounted) return;
if (response.statusCode == 200) { if (response.statusCode == 200) {
@@ -116,15 +112,15 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
_expectedFrequencyController.text = ''; _expectedFrequencyController.text = '';
}); });
if (!mounted) return; // Zweiter Check vor ScaffoldMessenger if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('SimBrief Daten erfolgreich geladen')), const SnackBar(content: Text('SimBrief data successfully loaded')),
); );
} }
} catch (e) { } catch (e) {
if (!mounted) return; // Check vor Error-SnackBar if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Fehler beim Laden der SimBrief Daten: $e')), SnackBar(content: Text('Error loading SimBrief data: $e')),
); );
} }
} }
@@ -250,22 +246,60 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
), ),
], ],
), ),
body: GestureDetector( body: LayoutBuilder(
// Dismiss the keyboard when tapping outside builder: (context, constraints) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(), onTap: () => FocusScope.of(context).unfocus(),
child: SingleChildScrollView( child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
// ConstrainedBox hinzufügen
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight - 100, // AppBar-Höhe abziehen
),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
// IntrinsicHeight Widget hinzufügen if (constraints.maxWidth > 600)
// Desktop Layout
IntrinsicHeight( IntrinsicHeight(
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch, // Stretch hinzufügen crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
// Welcome Card - nimmt 60% der Breite
Expanded( Expanded(
flex: 3, flex: 3,
child: Card( child: _buildWelcomeCard(),
),
const SizedBox(width: 16),
Expanded(
flex: 2,
child: _buildSimbriefCard(),
),
],
),
)
else
// Mobile Layout
Column(
children: [
_buildWelcomeCard(),
const SizedBox(height: 16),
_buildSimbriefCard(),
],
),
_buildMainContent(),
],
),
),
),
);
},
),
);
}
// Hilfsmethoden zum Erstellen der Cards
Widget _buildWelcomeCard() {
return Card(
elevation: 2, elevation: 2,
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
@@ -284,13 +318,11 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
], ],
), ),
), ),
), );
), }
const SizedBox(width: 16), // Abstand zwischen den Cards
// SimBrief Card - nimmt 40% der Breite Widget _buildSimbriefCard() {
Expanded( return Card(
flex: 2,
child: Card(
elevation: 2, elevation: 2,
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
@@ -334,13 +366,11 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
], ],
), ),
), ),
), );
), }
],
), Widget _buildMainContent() {
), return Card(
const SizedBox(height: 16),
Card(
elevation: 2, elevation: 2,
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
@@ -458,11 +488,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
], ],
), ),
), ),
),
],
),
),
),
); );
} }
} }