From 1cc3e6baf07590c243d7a90c52f5052f608d83f1 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 21 Mar 2025 17:56:31 -0500 Subject: [PATCH] added show/hide password buttons --- web/repertory/lib/helpers.dart | 2 +- web/repertory/lib/settings.dart | 146 +++++++++++++++++++++----------- 2 files changed, 96 insertions(+), 52 deletions(-) diff --git a/web/repertory/lib/helpers.dart b/web/repertory/lib/helpers.dart index 3935ecd1..39655aa8 100644 --- a/web/repertory/lib/helpers.dart +++ b/web/repertory/lib/helpers.dart @@ -347,7 +347,7 @@ Future promptPassword() async { obscuringCharacter: '*', onChanged: (value) => password = value, ), - title: const Text('Enter Authentication Password'), + title: const Text('Enter Repertory Portal Password'), ); }, ); diff --git a/web/repertory/lib/settings.dart b/web/repertory/lib/settings.dart index 36b8b266..a5d68e89 100644 --- a/web/repertory/lib/settings.dart +++ b/web/repertory/lib/settings.dart @@ -161,63 +161,107 @@ void createPasswordSetting( onPressed: (_) { String updatedValue1 = value; String updatedValue2 = value; + bool hidePassword1 = true; + bool hidePassword2 = true; showDialog( context: context, builder: (context) { - return AlertDialog( - actions: [ - TextButton( - child: const Text('Cancel'), - onPressed: () => Navigator.of(context).pop(), - ), - TextButton( - child: const Text('OK'), - onPressed: () { - if (updatedValue1 != updatedValue2) { - return displayErrorMessage( - context, - "Setting '$key' does not match", - ); - } + return StatefulBuilder( + builder: (context, setDialogState) { + return AlertDialog( + actions: [ + TextButton( + child: const Text('Cancel'), + onPressed: () => Navigator.of(context).pop(), + ), + TextButton( + child: const Text('OK'), + onPressed: () { + if (updatedValue1 != updatedValue2) { + return displayErrorMessage( + context, + "Setting '$key' does not match", + ); + } - final result = validators.firstWhereOrNull( - (validator) => !validator(updatedValue1), - ); - if (result != null) { - return displayErrorMessage( - context, - "Setting '$key' is not valid", - ); - } + final result = validators.firstWhereOrNull( + (validator) => !validator(updatedValue1), + ); + if (result != null) { + return displayErrorMessage( + context, + "Setting '$key' is not valid", + ); + } - setState(() => settings[key] = updatedValue1); - Navigator.of(context).pop(); - }, - ), - ], - content: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - autofocus: true, - controller: TextEditingController(text: updatedValue1), - obscureText: true, - obscuringCharacter: '*', - onChanged: (value) => updatedValue1 = value, + setState(() => settings[key] = updatedValue1); + Navigator.of(context).pop(); + }, + ), + ], + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + Expanded( + child: TextField( + autofocus: true, + controller: TextEditingController( + text: updatedValue1, + ), + obscureText: hidePassword1, + obscuringCharacter: '*', + onChanged: (value) => updatedValue1 = value, + ), + ), + IconButton( + onPressed: + () => setDialogState( + () => hidePassword1 = !hidePassword1, + ), + icon: Icon( + hidePassword1 + ? Icons.visibility + : Icons.visibility_off, + ), + ), + ], + ), + const SizedBox(height: constants.padding), + Row( + children: [ + Expanded( + child: TextField( + autofocus: false, + controller: TextEditingController( + text: updatedValue2, + ), + obscureText: hidePassword2, + obscuringCharacter: '*', + onChanged: (value) => updatedValue2 = value, + ), + ), + IconButton( + onPressed: + () => setDialogState( + () => hidePassword2 = !hidePassword2, + ), + icon: Icon( + hidePassword2 + ? Icons.visibility + : Icons.visibility_off, + ), + ), + ], + ), + ], ), - const SizedBox(height: constants.padding), - TextField( - autofocus: false, - controller: TextEditingController(text: updatedValue2), - obscureText: true, - obscuringCharacter: '*', - onChanged: (value) => updatedValue2 = value, - ), - ], - ), - title: createSettingTitle(context, key, description), + title: createSettingTitle(context, key, description), + ); + }, ); }, );