From 7bc3338c2a01add92ef7f89853c3c3c671282275 Mon Sep 17 00:00:00 2001 From: NBA2K1 <78034913+NBA2K1@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:12:18 +0100 Subject: [PATCH] Make login dialog code simpler - Remove unnecessary email and password state variables - Rely on TextEditingController values instead of onChanged - Reset error state on submit - Dispose controllers after dialog closes --- lib/modules/more/settings/track/track.dart | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/modules/more/settings/track/track.dart b/lib/modules/more/settings/track/track.dart index 03d0167f..02ff1bf3 100644 --- a/lib/modules/more/settings/track/track.dart +++ b/lib/modules/more/settings/track/track.dart @@ -82,9 +82,7 @@ class TrackScreen extends ConsumerWidget { entries: entries!, ), TrackListile( - onTap: () async { - _showDialogLogin(context, ref); - }, + onTap: () => _showDialogLogin(context, ref), id: TrackerProviders.kitsu.syncId, entries: entries, ), @@ -167,16 +165,14 @@ class TrackScreen extends ConsumerWidget { } } -void _showDialogLogin(BuildContext context, WidgetRef ref) { +Future _showDialogLogin(BuildContext context, WidgetRef ref) async { final passwordController = TextEditingController(); final emailController = TextEditingController(); - String email = ""; - String password = ""; String errorMessage = ""; bool isLoading = false; bool obscureText = true; final l10n = l10nLocalizations(context)!; - showDialog( + await showDialog( context: context, builder: (context) => StatefulBuilder( builder: (context, setState) { @@ -206,9 +202,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) { autofocus: true, onFieldSubmitted: (_) => FocusScope.of(context).nextFocus(), - onChanged: (value) => setState(() { - email = value; - }), decoration: InputDecoration( hintText: l10n.email_adress, filled: false, @@ -239,9 +232,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) { enableSuggestions: false, autocorrect: false, autofillHints: const [AutofillHints.password], - onChanged: (value) => setState(() { - password = value; - }), decoration: InputDecoration( hintText: l10n.password, suffixIcon: IconButton( @@ -285,7 +275,10 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) { : () async { setState(() { isLoading = true; + errorMessage = ""; }); + final email = emailController.text.trim(); + final password = passwordController.text; final res = await ref .read( kitsuProvider( @@ -320,4 +313,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) { }, ), ); + emailController.dispose(); + passwordController.dispose(); }