setKeys method

void setKeys({
  1. bool reset = false,
})

Ensures lib/src/config/app.json exists and populates it with default config.

If reset is true, overwrites existing config. Otherwise, only writes if file is missing or empty.

Sets:

  • name, version, timestamp
  • Secure key via generateKey
  • Unique id via UUID v4
  • debug: true

Implementation

void setKeys({bool reset = false}) {
  final file = File('lib/src/config/app.json');

  // Ensure file exists
  if (!file.existsSync()) {
    file.createSync(recursive: true);
    file.writeAsStringSync('{}');
  }

  String content = file.readAsStringSync();

  // Skip if content exists and not resetting
  if ((content.isNotEmpty && content != "{}") && !reset) return;

  final config = <String, dynamic>{
    "name": "Archery Web Application",
    "version": version,
    "timestamp": DateTime.now().toUtc().toIso8601String(),
    "key": generateKey(),
    "id": Uuid().v4(),
    "debug": true,
  };

  file.writeAsStringSync(json.encode(config));
}