generateEnvFile method
Generates a JSON ENV File For Dart Define
Implementation
Future<void> generateEnvFile() async {
// Define the JSON content for each environment
final Map<String, dynamic> devEnvironment = {
'apiBaseUrl': 'https://api.dev.example.com',
'debugMode': true,
};
final Map<String, dynamic> stagingEnvironment = {
'apiBaseUrl': 'https://api.staging.example.com',
'debugMode': true,
};
final Map<String, dynamic> prodEnvironment = {
'apiBaseUrl': 'https://api.prod.example.com',
'debugMode': false,
};
// Convert maps to JSON strings with prettified formatting
final devJson = const JsonEncoder.withIndent(' ').convert(devEnvironment);
final stagingJson =
const JsonEncoder.withIndent(' ').convert(stagingEnvironment);
final prodJson =
const JsonEncoder.withIndent(' ').convert(prodEnvironment);
// Write JSON content to files
await writeFile(
filePath: 'env_dev.json',
content: devJson,
);
await writeFile(
filePath: 'env_staging.json',
content: stagingJson,
);
await writeFile(
filePath: 'env_prod.json',
content: prodJson,
);
}