I'm using flutter to write an app for both iOS and Android platforms. Some functions are not the same.
For example:
if (Platform.isIOS) {
int onlyForiOS = 10;
onlyForiOS++;
print("$onlyForiOS");
}
else if (Platform.isAndroid){
int onlyForAndroid = 20;
onlyForAndroid++;
print("$onlyForAndroid");
}
When I build for the Android platform, will the codes for iOS be compiled into the binary file? Or they are just removed for optimization? For security reason, I don't want any of the codes for iOS appeared in the Android binary file.
This depends on what expression you are evaluating.
Dart tree-shaking is based on constant variables. As such, the following will be tree-shaked:
const foo = false;
if (foo) {
// will be removed on release builds
}
But this example won't:
final foo = false;
if (foo) {
// foo is not a const, therefore this if is not tree-shaked
}
Now if we look at the implementation of Platform.isAndroid
, we can see that it is not a constant, but instead a getter.
Therefore we can deduce that if (Platform.isAndroid)
won't be tree-shaked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With