android - 尽管调试 apk 运行良好,但 Flutter 发布 apk 无法正确重建我的小部件
问题描述
我有一个文字游戏应用程序,我给用户一个字母架来输入字母。当用户键入一个字母时,它进入一个数组,该数组反映在屏幕上的一个答案架上(如果用户选择正确的字母并说出正确的单词,他就会获得积分)这个应用程序的设置是letter rack 是一个单独的小部件,array 是由提供者管理的全局数组,而 answer rack 是另一个侦听该提供者的小部件。
在我的调试 apk 的情况下,当我输入一个字母时,它会完美地反映到答案架上,即用户输入一个字母 -> 一个函数将它添加到数组中 -> 答案架小部件正在监听管理数组的提供程序 - > 答案小部件重建,输入的字母反映在屏幕上。但是,在发布 apk 的情况下,最后一步不会发生,即小部件不会重建。字母被输入到我可以通过打印数组看到的数组中,但小部件不会重建。如果我通过点击屏幕上的某些按钮来强制重建,输入的字母会反映在屏幕上。
我已经尝试了 SOF 上建议的所有解决方案来解决调试和发布 apk 之间的问题,即
添加 Internet 权限
... <uses-permission android:name="android.permission.INTERNET"/> ... </manifest>```
颤振清理并重建以发布
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 is not working normal? 以及 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();
}
解决方案
推荐阅读
- selenium - 尝试使用 Selenium 单击 BeautifulSoup 返回的元素时出现“NoneType”对象不可调用错误
- excel - 在 Excel 中使用 Powershell 检查列中的所有单元格值以触发每行的复制和粘贴
- javascript - Jquery multiplication of two column value in table with form repeater
- php - IONOS 上的 htaccess 动态重定向问题
- nginx - 我们从 nginx 收到“18446744073709551615”响应,而不是正确的响应代码
- javascript - 基于计时器类,警告:在现有状态转换期间无法更新(例如在 `render` 中)
- c++ - 对头文件中的类成员函数和变量进行升序排序
- python - OSError [Errno -9988] 流在 Python 中关闭
- c# - 在单例中实例化预制件不起作用,即对象未实例化
- android - 如何将数据从广播接收器传递到回收器视图项