[英]Flutter release APK is not working but debug APK is working
My debug APK is working fine but release APK is not working after building it from the command flutter build apk
.我的调试 APK 工作正常,但发布 APK 在从命令
flutter build apk
后无法正常工作。 What can be the real issue here?这里真正的问题是什么?
In debug mode, any global variables or methods will work perfectly but in case of release mode, only native code is compiled.在调试模式下,任何全局变量或方法都可以正常工作,但在发布模式下,只编译本机代码。 So let's assume we are getting some unformatted text and we want to format it and return so if you have a global function to format text like below it will work fine in debug mode but might cause problems in release mode.
所以让我们假设我们得到一些未格式化的文本,我们想要格式化并返回,所以如果你有一个全局 function 来格式化文本,如下所示,它在调试模式下可以正常工作,但在发布模式下可能会导致问题。
Code with global function.编码为全局 function。
// Global Function
String formatText(String unformattedText){
// ....
return formattedText;
}
Widget _showFormattedText(String unformattedText) {
final fd = formatText(unformattedText);
return Text(fd);
}
Instead of this we should follow best practices and wrap everything inside a class which is present globally.取而代之的是,我们应该遵循最佳实践并将所有内容包装在全球存在的 class 中。
// Code with class method.
class CustomFunctions{
static String formatText(String unformattedText){
// ....
return formattedText;
}
}
Widget _showFormattedText(String unformattedText) {
final fd = CustomFunctions.formatText(unformattedText);
return Text(fd);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.