有没有可能确定我运行项目的环境?
flutter run --flavor prod
flutter run --flavor dev
dart side
@override
void initState() {
//THIS SHOULD BE WORK BOTH IOS AND ANDORID
const bool isProduction = bool.fromEnvironment('com.demo.store.prod');
if(isProduction) {
print('it is prod');
} else {
print('it is not prod');//always print this line
}
super.initState();
}
app/build.gradle - Android端
productFlavors {
dev {
dimension "app"
versionCode 1
versionName "1.0.0"
}
prod {
dimension "app"
applicationId "com.demo.store.prod"
versionCode 2
versionName "1.0.0"
}
}