Arguments.fromJson constructor

Arguments.fromJson(
  1. Map<String, dynamic> json, {
  2. required Variables variables,
})

Factory constructor creating Arguments from JSON configuration.

Deserializes a JSON object into a fully configured Arguments instance for custom build execution. This factory enables configuration loading from files, API responses, or serialized build configurations with comprehensive parameter mapping and type safety.

Parameters

  • json - Map containing build configuration parameters
  • variables - Required system and environment variables for build context

Returns

Returns a configured Arguments instance with:

  • All JSON parameters properly deserialized and typed
  • Required binary type and variables configuration
  • Optional parameters with null safety and default fallbacks
  • Custom arguments list properly cast from dynamic JSON array
  • Output and source directory paths with default value support

JSON Structure

Expected JSON format includes:

{
  "binary-type": "aab",
  "build-mode": "release",
  "target": "./lib/main.dart",
  "flavor": "production",
  "dart-defines": "FLAVOR=prod",
  "dart-defines-file": "./defines.json",
  "build-name": "2.1.0",
  "build-number": "42",
  "pub": true,
  "arguments": ["--verbose", "--analyze-size"],
  "output": "./custom-builds/",
  "build-source-dir": "./lib"
}

Type Handling

The factory performs careful type conversion:

  • String parameters cast directly from JSON values
  • Boolean parameters with null-safe defaults
  • List parameters safely cast from dynamic JSON arrays
  • Numeric parameters converted to string representation
  • Path parameters with default directory fallbacks

Example

final config = {
  'binary-type': 'ipa',
  'build-mode': 'release',
  'arguments': ['--verbose', '--tree-shake-icons'],
  'pub': true
};

final args = Arguments.fromJson(config, variables: systemVars);
final result = await args.build();

Implementation

factory Arguments.fromJson(
  Map<String, dynamic> json, {
  required Variables variables,
}) {
  return Arguments(
    variables,
    binaryType: json['binary-type'] as String,
    buildMode: json['build-mode'] as String?,
    target: json['target'] as String?,
    flavor: json['flavor'] as String?,
    dartDefines: json['dart-defines'] as String?,
    dartDefinesFile: json['dart-defines-file'] as String?,
    buildName: json['build-name']?.toString(),
    buildNumber: json['build-number'] as String?,
    pub: json['pub'] as bool? ?? true,
    customArgs: (json['arguments'] as List<dynamic>?)?.cast<String>(),
    output: json['output'] as String? ?? Files.customOutputDir.path,
    buildSourceDir:
        json['build-source-dir'] as String? ?? Files.customOutputDir.path,
  );
}