我正试图加密或解密一个字符串,这取决于我是否按了一个按钮。该算法之所以有效,是因为在我的控制台上,我得到了正确的结果:一旦按下按钮,解密的文本就会以我想要的方式显示。但是这个更改并没有显示在屏幕上,实际上加密的文本仍然存在,并且不会进行任何更改。如何确保一旦按下“显示单词列表”按钮,我的文本就会更改以显示解密的文本?
我的代码如下所示:
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();
},
),有人知道怎么帮我吗?谢谢!
发布于 2021-08-16 15:20:35
无论何时设置状态,密码实际上都是解密的,但是在构建方法的顶部有布尔检查,该方法总是被设置为true。在构建方法之外创建另一个布尔值,以检查是否解密或加密,默认为true,当您要显示它时,将其设置为false,您的函数将如下所示。
因此,在解密函数中,将此值更改为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.
});
}发布于 2021-08-16 15:18:29
decryptWordList完成后和外部使用setstate,并确保seedphrase值不会被其他任何东西更改!https://stackoverflow.com/questions/68805118
复制相似问题