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
This commit is contained in:
NBA2K1 2026-02-27 14:12:18 +01:00
parent f85e661c8e
commit 7bc3338c2a

View file

@ -82,9 +82,7 @@ class TrackScreen extends ConsumerWidget {
entries: entries!, entries: entries!,
), ),
TrackListile( TrackListile(
onTap: () async { onTap: () => _showDialogLogin(context, ref),
_showDialogLogin(context, ref);
},
id: TrackerProviders.kitsu.syncId, id: TrackerProviders.kitsu.syncId,
entries: entries, entries: entries,
), ),
@ -167,16 +165,14 @@ class TrackScreen extends ConsumerWidget {
} }
} }
void _showDialogLogin(BuildContext context, WidgetRef ref) { Future<void> _showDialogLogin(BuildContext context, WidgetRef ref) async {
final passwordController = TextEditingController(); final passwordController = TextEditingController();
final emailController = TextEditingController(); final emailController = TextEditingController();
String email = "";
String password = "";
String errorMessage = ""; String errorMessage = "";
bool isLoading = false; bool isLoading = false;
bool obscureText = true; bool obscureText = true;
final l10n = l10nLocalizations(context)!; final l10n = l10nLocalizations(context)!;
showDialog( await showDialog(
context: context, context: context,
builder: (context) => StatefulBuilder( builder: (context) => StatefulBuilder(
builder: (context, setState) { builder: (context, setState) {
@ -206,9 +202,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) {
autofocus: true, autofocus: true,
onFieldSubmitted: (_) => onFieldSubmitted: (_) =>
FocusScope.of(context).nextFocus(), FocusScope.of(context).nextFocus(),
onChanged: (value) => setState(() {
email = value;
}),
decoration: InputDecoration( decoration: InputDecoration(
hintText: l10n.email_adress, hintText: l10n.email_adress,
filled: false, filled: false,
@ -239,9 +232,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) {
enableSuggestions: false, enableSuggestions: false,
autocorrect: false, autocorrect: false,
autofillHints: const [AutofillHints.password], autofillHints: const [AutofillHints.password],
onChanged: (value) => setState(() {
password = value;
}),
decoration: InputDecoration( decoration: InputDecoration(
hintText: l10n.password, hintText: l10n.password,
suffixIcon: IconButton( suffixIcon: IconButton(
@ -285,7 +275,10 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) {
: () async { : () async {
setState(() { setState(() {
isLoading = true; isLoading = true;
errorMessage = "";
}); });
final email = emailController.text.trim();
final password = passwordController.text;
final res = await ref final res = await ref
.read( .read(
kitsuProvider( kitsuProvider(
@ -320,4 +313,6 @@ void _showDialogLogin(BuildContext context, WidgetRef ref) {
}, },
), ),
); );
emailController.dispose();
passwordController.dispose();
} }