7

I just started to learn Flutter. I use vscode as editor

I need to use json_serializable on my code. I read https://pub.dev/packages/json_serializable and make my build.yaml just like what show there.

targets:
  $default:
    builders:
      json_serializable:
        options:
          # Options configure how source code is generated for every
          # `@JsonSerializable`-annotated class in the package.
          #
          # The default value for each is listed.
          any_map: false
          checked: false
          constructor: ""
          create_factory: true
          create_to_json: true
          disallow_unrecognized_keys: false
          explicit_to_json: false
          field_rename: none
          generic_argument_factories: false
          ignore_unannotated: false
          include_if_null: true

but vscode say : Property targets is not allowed. yaml-schema: Hammerkit YAML Schema [1,1]

FYI, here is my pubspec.lock

# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  _fe_analyzer_shared:
    dependency: transitive
    description:
      name: _fe_analyzer_shared
      url: "https://pub.dartlang.org"
    source: hosted
    version: "29.0.0"
  analyzer:
    dependency: transitive
    description:
      name: analyzer
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.6.0"
  args:
    dependency: transitive
    description:
      name: args
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.3.0"
  async:
    dependency: transitive
    description:
      name: async
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.8.1"
  auto_route:
    dependency: "direct main"
    description:
      name: auto_route
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  auto_route_generator:
    dependency: "direct dev"
    description:
      name: auto_route_generator
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  boolean_selector:
    dependency: transitive
    description:
      name: boolean_selector
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  build:
    dependency: transitive
    description:
      name: build
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.1"
  build_config:
    dependency: transitive
    description:
      name: build_config
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0"
  build_daemon:
    dependency: transitive
    description:
      name: build_daemon
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  build_resolvers:
    dependency: transitive
    description:
      name: build_resolvers
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.4"
  build_runner:
    dependency: "direct dev"
    description:
      name: build_runner
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.5"
  build_runner_core:
    dependency: transitive
    description:
      name: build_runner_core
      url: "https://pub.dartlang.org"
    source: hosted
    version: "7.2.2"
  built_collection:
    dependency: transitive
    description:
      name: built_collection
      url: "https://pub.dartlang.org"
    source: hosted
    version: "5.1.1"
  built_value:
    dependency: transitive
    description:
      name: built_value
      url: "https://pub.dartlang.org"
    source: hosted
    version: "8.1.2"
  characters:
    dependency: transitive
    description:
      name: characters
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.0"
  charcode:
    dependency: transitive
    description:
      name: charcode
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.3.1"
  checked_yaml:
    dependency: transitive
    description:
      name: checked_yaml
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.1"
  cli_util:
    dependency: transitive
    description:
      name: cli_util
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.3.5"
  clock:
    dependency: transitive
    description:
      name: clock
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.0"
  code_builder:
    dependency: transitive
    description:
      name: code_builder
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.1.0"
  collection:
    dependency: transitive
    description:
      name: collection
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.15.0"
  convert:
    dependency: transitive
    description:
      name: convert
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  crypto:
    dependency: transitive
    description:
      name: crypto
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  cupertino_icons:
    dependency: "direct main"
    description:
      name: cupertino_icons
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.3"
  dart_style:
    dependency: transitive
    description:
      name: dart_style
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.2.0"
  dartz:
    dependency: "direct main"
    description:
      name: dartz
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.10.0"
  dio:
    dependency: "direct main"
    description:
      name: dio
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.0.0"
  fake_async:
    dependency: transitive
    description:
      name: fake_async
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.0"
  ffi:
    dependency: transitive
    description:
      name: ffi
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.2"
  file:
    dependency: transitive
    description:
      name: file
      url: "https://pub.dartlang.org"
    source: hosted
    version: "6.1.2"
  fixnum:
    dependency: transitive
    description:
      name: fixnum
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0"
  flash:
    dependency: "direct main"
    description:
      name: flash
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.3"
  flutter:
    dependency: "direct main"
    description: flutter
    source: sdk
    version: "0.0.0"
  flutter_hooks:
    dependency: "direct main"
    description:
      name: flutter_hooks
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.18.0"
  flutter_riverpod:
    dependency: transitive
    description:
      name: flutter_riverpod
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0-dev.11"
  flutter_secure_storage:
    dependency: "direct main"
    description:
      name: flutter_secure_storage
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.2.1"
  flutter_test:
    dependency: "direct dev"
    description: flutter
    source: sdk
    version: "0.0.0"
  freezed:
    dependency: "direct dev"
    description:
      name: freezed
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.15.0+1"
  freezed_annotation:
    dependency: "direct main"
    description:
      name: freezed_annotation
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.15.0"
  frontend_server_client:
    dependency: transitive
    description:
      name: frontend_server_client
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.2"
  glob:
    dependency: transitive
    description:
      name: glob
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.2"
  graphs:
    dependency: transitive
    description:
      name: graphs
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  hooks_riverpod:
    dependency: "direct main"
    description:
      name: hooks_riverpod
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0-dev.11"
  http:
    dependency: transitive
    description:
      name: http
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.13.4"
  http_multi_server:
    dependency: transitive
    description:
      name: http_multi_server
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  http_parser:
    dependency: transitive
    description:
      name: http_parser
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.0.0"
  io:
    dependency: transitive
    description:
      name: io
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.3"
  js:
    dependency: transitive
    description:
      name: js
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.6.3"
  json_annotation:
    dependency: "direct main"
    description:
      name: json_annotation
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.3.0"
  json_serializable:
    dependency: "direct dev"
    description:
      name: json_serializable
      url: "https://pub.dartlang.org"
    source: hosted
    version: "6.0.1"
  lint:
    dependency: "direct dev"
    description:
      name: lint
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.7.2"
  logging:
    dependency: transitive
    description:
      name: logging
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.2"
  matcher:
    dependency: transitive
    description:
      name: matcher
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.12.10"
  material_design_icons_flutter:
    dependency: "direct main"
    description:
      name: material_design_icons_flutter
      url: "https://pub.dartlang.org"
    source: hosted
    version: "5.0.6295"
  meta:
    dependency: transitive
    description:
      name: meta
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.7.0"
  mime:
    dependency: transitive
    description:
      name: mime
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0"
  oauth2:
    dependency: "direct main"
    description:
      name: oauth2
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.0"
  package_config:
    dependency: transitive
    description:
      name: package_config
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.2"
  path:
    dependency: "direct main"
    description:
      name: path
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.8.0"
  path_provider:
    dependency: "direct main"
    description:
      name: path_provider
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.6"
  path_provider_linux:
    dependency: transitive
    description:
      name: path_provider_linux
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  path_provider_macos:
    dependency: transitive
    description:
      name: path_provider_macos
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.2"
  path_provider_platform_interface:
    dependency: transitive
    description:
      name: path_provider_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.1"
  path_provider_windows:
    dependency: transitive
    description:
      name: path_provider_windows
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.3"
  platform:
    dependency: transitive
    description:
      name: platform
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.2"
  plugin_platform_interface:
    dependency: transitive
    description:
      name: plugin_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.2"
  pool:
    dependency: transitive
    description:
      name: pool
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.5.0"
  process:
    dependency: transitive
    description:
      name: process
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.2.4"
  pub_semver:
    dependency: transitive
    description:
      name: pub_semver
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  pubspec_parse:
    dependency: transitive
    description:
      name: pubspec_parse
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.0"
  riverpod:
    dependency: transitive
    description:
      name: riverpod
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0-dev.10"
  sembast:
    dependency: "direct main"
    description:
      name: sembast
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.1"
  shelf:
    dependency: transitive
    description:
      name: shelf
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.0"
  shelf_web_socket:
    dependency: transitive
    description:
      name: shelf_web_socket
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.1"
  sky_engine:
    dependency: transitive
    description: flutter
    source: sdk
    version: "0.0.99"
  source_gen:
    dependency: transitive
    description:
      name: source_gen
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.1"
  source_helper:
    dependency: transitive
    description:
      name: source_helper
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.3.0"
  source_span:
    dependency: transitive
    description:
      name: source_span
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.8.1"
  stack_trace:
    dependency: transitive
    description:
      name: stack_trace
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.10.0"
  state_notifier:
    dependency: transitive
    description:
      name: state_notifier
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.7.1"
  stream_channel:
    dependency: transitive
    description:
      name: stream_channel
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  stream_transform:
    dependency: transitive
    description:
      name: stream_transform
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.0"
  string_scanner:
    dependency: transitive
    description:
      name: string_scanner
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.0"
  synchronized:
    dependency: transitive
    description:
      name: synchronized
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.0"
  term_glyph:
    dependency: transitive
    description:
      name: term_glyph
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.0"
  test_api:
    dependency: transitive
    description:
      name: test_api
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.2"
  timing:
    dependency: transitive
    description:
      name: timing
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.0"
  typed_data:
    dependency: transitive
    description:
      name: typed_data
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.3.0"
  vector_math:
    dependency: transitive
    description:
      name: vector_math
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  watcher:
    dependency: transitive
    description:
      name: watcher
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.1"
  web_socket_channel:
    dependency: transitive
    description:
      name: web_socket_channel
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  webview_flutter:
    dependency: "direct main"
    description:
      name: webview_flutter
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.1"
  webview_flutter_android:
    dependency: transitive
    description:
      name: webview_flutter_android
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.15"
  webview_flutter_platform_interface:
    dependency: transitive
    description:
      name: webview_flutter_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.0"
  webview_flutter_wkwebview:
    dependency: transitive
    description:
      name: webview_flutter_wkwebview
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.14"
  win32:
    dependency: transitive
    description:
      name: win32
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.2.10"
  xdg_directories:
    dependency: transitive
    description:
      name: xdg_directories
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.2.0"
  yaml:
    dependency: transitive
    description:
      name: yaml
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.0"
sdks:
  dart: ">=2.14.0 <3.0.0"
  flutter: ">=2.5.0"

So kindly pelase tell me how to write proper build.yaml for flutter.

Note : I need to change explicit_to_json value to true

Sincerely

-bino-

Bino Oetomo
  • 571
  • 1
  • 10
  • 23
  • I think you can ignore the warning because its still work when the build_runner is run with the above `build.yaml` . See related `build.yaml` used in `json_serializable` package: https://github.com/google/json_serializable.dart/blob/master/json_serializable/build.yaml – ישו אוהב אותך Nov 12 '21 at 05:37

1 Answers1

17

You need to add a valid JSONSchema for the dart build system build.yaml file, or disable it, but I don't know how to do that on VSCode as I don't use it.

A valid Dart Build System JSONSchema is available from schemastore.org, search the page for Dart build configuration and grab the link from it - at the time of this answer the link is https://json.schemastore.org/dart-build.json.

To add a valid schema to VSCode, you first need to install the redhat.vscode-yaml extension and then add the block below to your settings.

"yaml.schemas": {
  "https://json.schemastore.org/dart-build.json": [
    "build.yaml"
  ]
},

Credit to: @simolus3 for the above info on how to add the schema to vscode taken from this link. NOTE: The above snippet is using the correct URL at the time of the answer.

For anyone using Android Studio (or similar IntelliJ product) and looking to resolve the same kind of error, click on Preferences and search for JSON Schema Mappings in the search box, click on the JSON Schema Mappings option on the left pane then click the + button on the right pane and fill in the details with a meaningful name possibly Dart Build System, the above URL, select JSON Schema version 7 from the drop down then click the + button at the bottom of the right hand pane to add the build.yaml file name (and any others you might want)e.g.

JSONSchema Setup in Android Studio

andye
  • 275
  • 3
  • 13