Is there a way by which I can change my default flutter app name to some other name(one that I prefer) in codemagic. I am using the automated workflow provided by codemagic. What I was thinking is to use a script either pre build for which I have written a dart code below :
import 'package:fresh_operator/core/utils/flavor_config.dart';
import 'package:logger/logger.dart';
import 'package:package_info/package_info.dart';
class VersionUtils {
final logger = Logger(printer: PrettyPrinter(colors: true));
// Function to generate build name
Future<String> generateBuildName() async {
var currentDate = DateTime.now().toLocal();
String releaseVersionNumber = await getAppVersionNumber();
late int patchNumber;
if (releaseVersionNumber == '2') {
patchNumber = 1;
}
String flavorName = Flavors.prod.toString();
String buildName =
'fresh_operator_${flavorName}_${currentDate.year}.$releaseVersionNumber.${patchNumber++}';
return buildName;
}
// This creates your app version number
Future<String> getAppVersionNumber() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String releaseVersionNumber = packageInfo.version;
return releaseVersionNumber;
}
}
Problem here is how to use the different app name for different flavors as well a precise logic when a release number is changed then the patchNumber shall start from 1. For example : fresh_operator_prod_2023.1.5 when jumped to release version 2 it should be something like fresh_operator_prod_2023.2.1
I tried putting a block inside the build.gradle from certain source for creating app name pre build but that didn't work because the gradle cannot refer to a dart file.
You can run the
dartscript via the command line to store the app name as output in your dart file.e.g.
here is the sample script
version.dartAfter running the above command, the output of the Dart script is now stored in the
APP_NAMEvariable. You can use it in subsequent commands as you'd like.Feel free to edit the
dartscript as per your requirements.