Text does not change if the button is pressed - FLUTTER

119

Whenever you setstate, the password is indeed decrypted, but you have boolean check on top inside your build method, which is always set to true. Create another boolean, to check if decrypted or encrypted, outside your build method, the default is true, and when you want to show it, set it to false, your function will look like this.

So, inside the decrypt function, change this value to false:


String seedphrase = state.seedphrase;
bool encrypted =true;  //Create this in your widget, directly before `Widget build...etc`
    
.
.
.
if(SettingsPage.passwordCreated == true && encrypted) {
  seedphrase = AesEncryptionDecryption
              .encryptAES(
              seedphrase)
              .base64;}
.
.
.
.
.
 void decryptWordList() {
            setState(() {
            seedphrase = AesEncryptionDecryption.decryptAES(seedphrase);
            encrypted =false; //Add this.
            });
          }
Share:
119
Simospa
Author by

Simospa

Updated on December 19, 2022

Comments

  • Simospa
    Simospa 11 months

    I'm trying to encrypt or decrypt a string depending on whether I press a button or not. The algorithm works because on my console I get the right result: once the button is pressed, the decrypted text is shown as I want. But this change is not shown on the screen, in fact the encrypted text remains and does not undergo any changes. How can I make sure that once the 'Show Word List' button is pressed, my text changes to show the decrypted text?

    I show below my code:

          String seedphrase = state.seedphrase;
          bool seedphraseforCrypted = true;
            
        
            if(SettingsPage.passwordCreated == true && seedphraseforCrypted == true) {
              seedphrase = AesEncryptionDecryption
                  .encryptAES(
                  seedphrase)
                  .base64;
            }
    
    
         void decryptWordList() {
                setState(() {
                  seedphrase = AesEncryptionDecryption.decryptAES(
                      seedphrase);
                });
         seedphraseforCrypted = false;
              }
    
          child: RichText(
                  text: TextSpan(
                    children: [
                      TextSpan(
                        text: seedphrase,
                          style: GoogleFonts.encodeSansSemiCondensed(fontSize: 18.0, fontWeight: FontWeight.w400,color: Palette.textColor)
                      ),
                      WidgetSpan(
                        child: Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 8.0),
                          child: Icon(
                            FeatherIcons.copy,
                            size: 25,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
        
         RoundedButton(
                text: 'Show Word List',
                selected: true,
                onPressed: ()  {
                   decryptWordList();
                 
                },
              ),
    

    does anyone know how to help me? thank you !

  • Simospa
    Simospa about 2 years
    I need the SettingsPage.passwordCreated value so I tried to create a new boolean variable to pass to the method but it still doesn't work, I edited the changes made above.
  • Huthaifa Muayyad
    Huthaifa Muayyad about 2 years
    I edited my answer, should work now, check it please.
  • Simospa
    Simospa about 2 years
    i corrected as you showed me but the text still doesn't change as i get the decrypted text on my console.