我有一个文字游戏应用程序,在其中我为用户提供了一个字母架来输入字母。当用户键入一个字母时,它会进入一个数组,该数组会反映到屏幕上的答案架中(如果用户选择正确的字母并说出正确的单词,他就会获得分数)。字母架是一个单独的小部件,数组是由提供者管理的全局数组,答案架是另一个监听该提供者的小部件。
在我的调试 apk 中,当我输入一个字母时,它会完美地反映到答案架上,即用户输入一个字母 -> 一个函数将其添加到数组中 -> 答案架小部件正在监听管理数组的提供者-> 答案小部件会重建,并且键入的字母会反映在屏幕上。但是,如果是发布 apk,则最后一步不会发生,即小部件不会重建。该字母被输入到数组中,我可以通过打印数组来看到该数组,但小部件不会重建。如果我通过点击屏幕上的某些按钮来强制重建,键入的字母就会反映在屏幕上。
我已经尝试了 SOF 上建议的所有解决方案来解决调试和发布 apk 之间的问题,即
添加互联网权限
...
<uses-permission android:name="android.permission.INTERNET"/>
...
</manifest>```
Flutter 清理并重建以发布
flutter build apk --release```
删除 ShrinkResources 和 MinifyEnabled。我已经尝试将这两个选项设置为 true 和 false。注意:我正在使用 ProGuard,如果删除它,我将无法编译
release {
signingConfig signingConfigs.config
shrinkResources false
minifyEnabled false
}
}```
我还将这些内容添加到我的 ProGuardRules.pro 文件中:
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
总之,我已经尝试了这里的所有方法:Flutter Release apk 无法正常工作? 以及 SOF 中给出的其他解决方案但无济于事。
任何人都可以帮助我了解我还能做什么。
这是提供程序中更新数组的函数的代码。整个代码有很多要粘贴到这里,因此只需添加主要片段即可。注意:数组一开始是空的,但是当用户删除数组中任何位置的字母时,我们将其替换为空格。因此,您将看到我们用点击的字母替换第一个空格的代码。
void updateLetters(String part, String letter, int index) {
int p1Space; // flag if part 1 has any spaces
int p2Space; // flag if part 2 has any spaces
p1Space = typedLetters_1.indexOf(' ');
p2Space = typedLetters_2.indexOf(' ');
wrongAnswer = false;
showCorrectMsg = false; // flag to show 'Thats Correct'
showWrongMsg = false; // Flag to show 'Try again'
if (part == 'part_1' &&
typedLetters_1.length <= _clueList[_questionIndex].answer_1.length) {
if (p1Space != -1) {
typedLetters_1.replaceRange(p1Space, p1Space + 1, [letter]);
reduceBoxSize(index, part);
} else if (typedLetters_1.length <
_clueList[_questionIndex].answer_1.length) {
typedLetters_1.add(letter);
typedIndex1.add(index);
reduceBoxSize(index, part);
}
} else if (part == 'part_2' &&
typedLetters_2.length <= _clueList[_questionIndex].answer_2.length) {
if (p2Space != -1) {
typedLetters_2.replaceRange(p2Space, p2Space + 1, [letter]);
reduceBoxSize(index, part);
} else if (typedLetters_2.length <
_clueList[_questionIndex].answer_2.length) {
typedLetters_2.add(letter);
typedIndex2.add(index);
reduceBoxSize(index, part);
}
}
checkAnswer(part);
}
void checkAnswer(String part) {
int p1Space;
int p2Space;
if (part == 'part_1' &&
typedLetters_1.length == _clueList[_questionIndex].answer_1.length) {
String userAns_1 = typedLetters_1.join('');
if (userAns_1.toUpperCase() ==
_clueList[_questionIndex].answer_1.toUpperCase()) {
part1Correct = true;
wrongAnswer = false;
showCorrectMsg = true;
} else {
wrongAnswer = true;
p1Space = typedLetters_1.indexOf(
' '); // checking again if any open spaces are still present - only if not show try again msg
if (p1Space == -1) showWrongMsg = true;
}
}
if (part == 'part_2' &&
typedLetters_2.length == _clueList[_questionIndex].answer_2.length) {
String userAns_2 = typedLetters_2.join('');
if (userAns_2.toUpperCase() ==
_clueList[_questionIndex].answer_2.toUpperCase()) {
part2Correct = true;
wrongAnswer = false;
showCorrectMsg = true;
} else {
wrongAnswer = true;
p2Space = typedLetters_2.indexOf(' ');
if (p2Space == -1) showWrongMsg = true;
}
}
if (part1Correct == true && part2Correct == true) rightAnswer = true;
notifyListeners();
}
当提供程序发生更改时,小部件树不会重建,因此为了使小部件树重建,请在更改提供程序变量时使用下面的空 setState((){})。