From 5c157c59b846ace3744eb90495adb8f788660e58 Mon Sep 17 00:00:00 2001 From: Pete Gregory Date: Wed, 6 Aug 2025 01:05:49 +0100 Subject: [PATCH] calculator and login improvements --- lib/components/calculator/calculator.dart | 17 +++++++++++++++++ lib/components/login/login.dart | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/components/calculator/calculator.dart b/lib/components/calculator/calculator.dart index 6f293ec..3fd3e90 100644 --- a/lib/components/calculator/calculator.dart +++ b/lib/components/calculator/calculator.dart @@ -66,9 +66,26 @@ class _StationAutocompleteState extends State { fieldViewBuilder: (context, textEditingController, focusNode, onFieldSubmitted) { textEditingController.value = _controller.value; + return TextField( controller: textEditingController, focusNode: focusNode, + textInputAction: TextInputAction.done, + onSubmitted: (_) { + final query = textEditingController.text.toLowerCase(); + final matches = widget.allStations + .map((s) => s.name) + .where((name) => name.toLowerCase().contains(query)) + .toList(); + + if (matches.isNotEmpty) { + matches.sort((a, b) => a.length.compareTo(b.length)); + final firstMatch = matches.first; + _controller.text = firstMatch; + widget.onChanged(firstMatch); + focusNode.unfocus(); // optionally close keyboard + } + }, decoration: const InputDecoration( labelText: 'Select station', border: OutlineInputBorder(), diff --git a/lib/components/login/login.dart b/lib/components/login/login.dart index b505d23..194803e 100644 --- a/lib/components/login/login.dart +++ b/lib/components/login/login.dart @@ -125,7 +125,7 @@ class _LoginPanelContentState extends State { _loggingIn = true; }); try { - auth.login(username, password); + await auth.login(username, password); print('Login successful'); setState(() { _loggingIn = false; @@ -148,7 +148,14 @@ class _LoginPanelContentState extends State { if (_loggingIn) { loginButtonContent = Padding( padding: const EdgeInsets.all(8.0), - child: CircularProgressIndicator(), + child: SizedBox( + height: 10, + width: 10, + child: CircularProgressIndicator( + color: Theme.of(context).textTheme.bodyLarge?.color, + strokeWidth: 2, + ), + ), ); } else { loginButtonContent = Text("Login");