From 18128114f68a2901cf2951cd2286fa1080b8474e Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Thu, 7 Aug 2025 15:42:29 +0530 Subject: [PATCH] fix: remove unnecessary setState when the value changes, which causes the EnvAuthField widget to rebuild and the cursor position to reset --- .../common_widgets/auth/oauth1_fields.dart | 41 +++--------- .../common_widgets/auth/oauth2_field.dart | 67 +++++++------------ 2 files changed, 35 insertions(+), 73 deletions(-) diff --git a/lib/screens/common_widgets/auth/oauth1_fields.dart b/lib/screens/common_widgets/auth/oauth1_fields.dart index 45fa7888..f89a7ba1 100644 --- a/lib/screens/common_widgets/auth/oauth1_fields.dart +++ b/lib/screens/common_widgets/auth/oauth1_fields.dart @@ -96,9 +96,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1ConsumerKey, infoText: kInfoOAuth1ConsumerKey, onChanged: (value) { - setState(() { - _consumerKey = value; - }); + _consumerKey = value; _updateOAuth1(); }, ), @@ -110,9 +108,7 @@ class _OAuth1FieldsState extends ConsumerState { infoText: kInfoOAuth1ConsumerSecret, isObscureText: true, onChanged: (value) { - setState(() { - _consumerSecret = value; - }); + _consumerSecret = value; _updateOAuth1(); }, ), @@ -134,10 +130,7 @@ class _OAuth1FieldsState extends ConsumerState { ? null : (OAuth1SignatureMethod? newAlgo) { if (newAlgo != null) { - setState(() { - _signatureMethodController = newAlgo; - }); - + _signatureMethodController = newAlgo; _updateOAuth1(); } }, @@ -149,9 +142,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1AccessToken, infoText: kInfoOAuth1AccessToken, onChanged: (value) { - setState(() { - _accessToken = value; - }); + _accessToken = value; _updateOAuth1(); }, ), @@ -163,9 +154,7 @@ class _OAuth1FieldsState extends ConsumerState { infoText: kInfoOAuth1TokenSecret, isObscureText: true, onChanged: (value) { - setState(() { - _tokenSecret = value; - }); + _tokenSecret = value; _updateOAuth1(); }, ), @@ -176,9 +165,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1CallbackUrl, infoText: kInfoOAuth1CallbackUrl, onChanged: (value) { - setState(() { - _callbackUrl = value; - }); + _callbackUrl = value; _updateOAuth1(); }, ), @@ -189,9 +176,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1Verifier, infoText: kInfoOAuth1Verifier, onChanged: (value) { - setState(() { - _verifier = value; - }); + _verifier = value; _updateOAuth1(); }, ), @@ -202,9 +187,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1Timestamp, infoText: kInfoOAuth1Timestamp, onChanged: (value) { - setState(() { - _timestamp = value; - }); + _timestamp = value; _updateOAuth1(); }, ), @@ -215,9 +198,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1Nonce, infoText: kInfoOAuth1Nonce, onChanged: (value) { - setState(() { - _nonce = value; - }); + _nonce = value; _updateOAuth1(); }, ), @@ -228,9 +209,7 @@ class _OAuth1FieldsState extends ConsumerState { hintText: kHintOAuth1Realm, infoText: kInfoOAuth1Realm, onChanged: (value) { - setState(() { - _realm = value; - }); + _realm = value; _updateOAuth1(); }, ), diff --git a/lib/screens/common_widgets/auth/oauth2_field.dart b/lib/screens/common_widgets/auth/oauth2_field.dart index 2ec52fe1..8af62f8e 100644 --- a/lib/screens/common_widgets/auth/oauth2_field.dart +++ b/lib/screens/common_widgets/auth/oauth2_field.dart @@ -145,9 +145,7 @@ class _OAuth2FieldsState extends ConsumerState { ? null : (OAuth2GrantType? newGrantType) { if (newGrantType != null && newGrantType != _grantType) { - setState(() { - _grantType = newGrantType; - }); + _grantType = newGrantType; _updateOAuth2(); } @@ -162,9 +160,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2AuthorizationUrl, infoText: kInfoOAuth2AuthorizationUrl, onChanged: (value) { - setState(() { - _authorizationUrl = value; - }); + _authorizationUrl = value; + _updateOAuth2(); }, ), @@ -177,9 +174,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2Username, infoText: kInfoOAuth2Username, onChanged: (value) { - setState(() { - _username = value; - }); + _username = value; + _updateOAuth2(); }, ), @@ -193,9 +189,8 @@ class _OAuth2FieldsState extends ConsumerState { infoText: kInfoOAuth2Password, isObscureText: true, onChanged: (value) { - setState(() { - _password = value; - }); + _password = value; + _updateOAuth2(); }, ), @@ -208,9 +203,7 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2AccessTokenUrl, infoText: kInfoOAuth2AccessTokenUrl, onChanged: (value) { - setState(() { - _accessTokenUrl = value; - }); + _accessTokenUrl = value; _updateOAuth2(); }, ), @@ -223,9 +216,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2ClientId, infoText: kInfoOAuth2ClientId, onChanged: (value) { - setState(() { - _clientId = value; - }); + _clientId = value; + _updateOAuth2(); }, ), @@ -239,9 +231,8 @@ class _OAuth2FieldsState extends ConsumerState { infoText: kInfoOAuth2ClientSecret, isObscureText: true, onChanged: (value) { - setState(() { - _clientSecret = value; - }); + _clientSecret = value; + _updateOAuth2(); }, ), @@ -265,9 +256,7 @@ class _OAuth2FieldsState extends ConsumerState { : (String? newMethod) { if (newMethod != null && newMethod != _codeChallengeMethod) { - setState(() { - _codeChallengeMethod = newMethod; - }); + _codeChallengeMethod = newMethod; _updateOAuth2(); } @@ -283,9 +272,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2RedirectUrl, infoText: kInfoOAuth2RedirectUrl, onChanged: (value) { - setState(() { - _redirectUrl = value; - }); + _redirectUrl = value; + _updateOAuth2(); }, ), @@ -298,9 +286,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2Scope, infoText: kInfoOAuth2Scope, onChanged: (value) { - setState(() { - _scope = value; - }); + _scope = value; + _updateOAuth2(); }, ), @@ -313,9 +300,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2State, infoText: kInfoOAuth2State, onChanged: (value) { - setState(() { - _state = value; - }); + _state = value; + _updateOAuth2(); }, ), @@ -338,9 +324,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2RefreshToken, infoText: kInfoOAuth2RefreshToken, onChanged: (value) { - setState(() { - _refreshToken = value; - }); + _refreshToken = value; + _updateOAuth2(); }, ), @@ -352,9 +337,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2IdentityToken, infoText: kInfoOAuth2IdentityToken, onChanged: (value) { - setState(() { - _identityToken = value; - }); + _identityToken = value; + _updateOAuth2(); }, ), @@ -369,9 +353,8 @@ class _OAuth2FieldsState extends ConsumerState { hintText: kHintOAuth2AccessToken, infoText: kInfoOAuth2AccessToken, onChanged: (value) { - setState(() { - _accessToken = value; - }); + _accessToken = value; + _updateOAuth2(); }, ),