createEnvironmentFile method Null safety

Future<void> createEnvironmentFile()

Implementation

Future<void> createEnvironmentFile () async {
  String token = '';
  Console.info(message: 'We will create your environment file..');

  final withToken = Confirm(
    prompt: 'Would you like to define your token now?',
    defaultValue: true,
  ).interact();

  if (!withToken) {
    Console.warn(message: 'Don\'t forget to set your token before restarting your application');
  } else {
    token = Input(prompt: 'What is your token ?').interact();
  }

  final environmentFile = File(join(Directory.current.path, '.env'));
  final sink = environmentFile.openWrite();
  sink.write(['APP_NAME: My mineral application', 'APP_TOKEN: $token', 'LOG_LEVEL: info', 'REPORTER: debug'].join('\n'));

  await sink.flush();
  await sink.close();
}