Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ Uniformise setPassword and setYubikey widgets #1048

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ui/views/authenticate/set_password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _SetPasswordState extends ConsumerState<SetPassword>
localizations.confirm,
Dimens.buttonTopDimens,
key: const Key('confirm'),
onPressed: _validateRequest,
onPressed: validate,
disabled: isProcessing,
),
],
Expand Down Expand Up @@ -348,7 +348,7 @@ class _SetPasswordState extends ConsumerState<SetPassword>
autocorrect: false,
controller: pwdConfirmController,
obscureText: !setPasswordVisible!,
onSubmitted: (_) => _validateRequest(),
onSubmitted: (_) => validate(),
onChanged: (text) async {
if (passwordError != null) {
setState(() {
Expand Down Expand Up @@ -434,7 +434,7 @@ class _SetPasswordState extends ConsumerState<SetPassword>
);
}

Future<void> _validateRequest() async {
Future<void> validate() async {
final localizations = AppLocalizations.of(context)!;

if (isProcessing) return;
Expand Down
59 changes: 32 additions & 27 deletions lib/ui/views/authenticate/set_yubikey_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@ class SetYubikey extends ConsumerStatefulWidget {

class _SetYubikeyState extends ConsumerState<SetYubikey>
implements SheetSkeletonInterface {
FocusNode? _clientIDFocusNode;
TextEditingController? _clientIDController;
FocusNode? _clientAPIKeyFocusNode;
TextEditingController? _clientAPIKeyController;
bool? animationOpen;
String _clientIDValidationText = '';
String _clientAPIKeyValidationText = '';
late FocusNode clientIDFocusNode;
late TextEditingController clientIDController;
late FocusNode clientAPIKeyFocusNode;
late TextEditingController clientAPIKeyController;
String clientIDValidationText = '';
String clientAPIKeyValidationText = '';

@override
void initState() {
super.initState();
_clientAPIKeyFocusNode = FocusNode();
_clientIDFocusNode = FocusNode();
_clientAPIKeyController = TextEditingController();
_clientIDController = TextEditingController();
animationOpen = false;
clientAPIKeyFocusNode = FocusNode();
clientIDFocusNode = FocusNode();
clientAPIKeyController = TextEditingController();
clientIDController = TextEditingController();
}

@override
void dispose() {
clientAPIKeyFocusNode.dispose();
clientIDFocusNode.dispose();
clientAPIKeyController.dispose();
clientIDController.dispose();
super.dispose();
}

@override
Expand All @@ -70,9 +77,7 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
localizations.confirm,
Dimens.buttonTopDimens,
key: const Key('confirm'),
onPressed: () async {
await validate();
},
onPressed: validate,
),
],
);
Expand Down Expand Up @@ -136,7 +141,7 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
alignment: AlignmentDirectional.center,
margin: const EdgeInsets.only(top: 3),
child: Text(
_clientIDValidationText,
clientIDValidationText,
style: ArchethicThemeStyles.textStyleSize14W600Primary,
),
),
Expand All @@ -151,7 +156,7 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
alignment: AlignmentDirectional.center,
margin: const EdgeInsets.only(top: 3),
child: Text(
_clientAPIKeyValidationText,
clientAPIKeyValidationText,
style: ArchethicThemeStyles.textStyleSize14W600Primary,
),
),
Expand Down Expand Up @@ -203,14 +208,14 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
fontSize: 14,
),
autocorrect: false,
controller: _clientIDController,
controller: clientIDController,
textInputAction: TextInputAction.next,
onChanged: (value) async {
setState(() {
_clientIDValidationText = '';
clientIDValidationText = '';
});
},
focusNode: _clientIDFocusNode,
focusNode: clientIDFocusNode,
keyboardType: TextInputType.text,
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(10),
Expand Down Expand Up @@ -277,15 +282,15 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
fontSize: 14,
),
autocorrect: false,
controller: _clientAPIKeyController,
controller: clientAPIKeyController,
textInputAction: TextInputAction.done,
autofocus: true,
onChanged: (value) async {
setState(() {
_clientAPIKeyValidationText = '';
clientAPIKeyValidationText = '';
});
},
focusNode: _clientAPIKeyFocusNode,
focusNode: clientAPIKeyFocusNode,
keyboardType: TextInputType.text,
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(40),
Expand All @@ -312,20 +317,20 @@ class _SetYubikeyState extends ConsumerState<SetYubikey>
}

Future<void> validate() async {
final clientId = _clientIDController!.text;
final clientApiKey = _clientAPIKeyController!.text;
final clientId = clientIDController.text;
final clientApiKey = clientAPIKeyController.text;

if (clientId.isEmpty) {
setState(() {
_clientIDValidationText =
clientIDValidationText =
AppLocalizations.of(context)!.enterYubikeyClientIDEmpty;
});
return;
}

if (clientApiKey.isEmpty) {
setState(() {
_clientAPIKeyValidationText =
clientAPIKeyValidationText =
AppLocalizations.of(context)!.enterYubikeyAPIKeyEmpty;
});
return;
Expand Down