toJson method

  1. @override
Map<String, dynamic> toJson()
override

Serializes the Arguments instance to a JSON-compatible map.

Converts all build configuration parameters into a JSON-serializable map structure that can be stored, transmitted, or used for configuration persistence. This method provides the inverse operation of fromJson for complete serialization support.

Returns

Returns a Map<String, dynamic> containing:

  • All build configuration parameters as key-value pairs
  • JSON-compatible data types (String, bool, List, etc.)
  • Null values preserved for optional parameters
  • Consistent key naming matching command-line arguments

Output Structure

The returned map structure includes:

  • binary-type - Output binary format specification
  • build-mode - Build optimization mode setting
  • target - Main application entry-point file
  • flavor - Product flavor or build variant
  • dart-defines - Dart compilation define values
  • dart-defines-file - Dart defines configuration file
  • build-name - Human-readable version name
  • build-number - Numeric version identifier
  • pub - Dependency resolution flag
  • arguments - Custom build command arguments
  • output - Build artifacts output directory

Example

final args = Arguments(variables, binaryType: 'aab', buildMode: 'release');
final json = args.toJson();

// Result:
// {
//   'binary-type': 'aab',
//   'build-mode': 'release',
//   'target': null,
//   'flavor': null,
//   'pub': null,
//   'arguments': null,
//   'output': null
// }

Implementation

@override
Map<String, dynamic> toJson() => {
  'binary-type': binaryType,
  'build-mode': buildMode,
  'target': target,
  'flavor': flavor,
  'dart-defines': dartDefines,
  'dart-defines-file': dartDefinesFile,
  'build-name': buildName,
  'build-number': buildNumber,
  'pub': pub,
  'arguments': customArgs,
  'output': output,
};