当试图用toJson函数生成冻结的数据模型时,我得到了以下错误。
Could not generate toJson code for merchants because of type Merchant.
这在Flutter 2.0及更高版本中开始发生。类型被定义并编译得很好,当我试图生成代码时,我会遇到错误。我正在使用:
Flutter 2.0.3
冷冻:0.12.7冷冻_注释:0.12.0
json_annotation:3.1.1json_serializable:3.5.1
build_runner:1.11.1
我还使用零安全颤振项目将所有内容更新到了最新版本,这种情况仍然存在,所以我知道这不是零安全问题。或者,至少我可以假设,当项目更新为空安全时,它不起作用。
这是最小的可复制模型集
@freezed
abstract class SearchInformation with _$SearchInformation {
SearchInformation._();
factory SearchInformation({
String query,
// List<CartProduct> products,
List<Merchant> merchants,
}) = _SearchInformation;
bool get hasSearchResults =>
(products != null && products.isNotEmpty) ||
(merchants != null && merchants.isNotEmpty);
int get searchCount => (products?.length ?? 0) + (merchants?.length ?? 0);
factory SearchInformation.fromJson(Map<String, dynamic> json) =>
_$SearchInformationFromJson(json);
}
@freezed
abstract class Merchant with _$Merchant {
factory Merchant({
int id,
}) = _Merchant;
}
我有一个问题。这已经21天没有答案了,甚至只是看了一眼。我不知道这是冷冻的还是json可序列化的。以下是错误发生时生成器输出的详细日志。我删除了一些重复的日志以使其更短,因为它是大量的文本。
flutter pub run build_runner build --delete-conflicting-outputs --verbose
[ +68 ms] executing: [C:srcflutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +64 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[ ] 60bd88df915880d23877bfc1602e8ddcf4c4dd2a
[ ] executing: [C:srcflutter/] git tag --points-at 60bd88df915880d23877bfc1602e8ddcf4c4dd2a
[ +57 ms] Exit code 0 from: git tag --points-at 60bd88df915880d23877bfc1602e8ddcf4c4dd2a
[ ] 2.0.0
[ +34 ms] executing: [C:srcflutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +35 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/stable
[ ] executing: [C:srcflutter/] git ls-remote --get-url origin
[ +32 ms] Exit code 0 from: git ls-remote --get-url origin
[ ] https://github.com/flutter/flutter.git
[ +66 ms] executing: [C:srcflutter/] git rev-parse --abbrev-ref HEAD
[ +34 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[ ] stable
[ +71 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ +11 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ +8 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +49 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[ ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ +8 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[ +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[ +24 ms] Using C:srcflutter.pub-cache for the pub cache.
[ +4 ms] executing: C:srcflutterbincachedart-sdkbinpub.bat run build_runner build --delete-conflicting-outputs --verbose
[INFO] Generating build script...
[INFO] Generating build script completed, took 390ms
[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 10.0s
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Building new asset graph...
[INFO] BuildDefinition:Building new asset graph completed, took 1.1s
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs....
[INFO] BuildDefinition:Deleting 2 declared outputs which already existed on disk.
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 2ms
[INFO] Build:Running build...
[INFO] Heartbeat:1.1s elapsed, 0/16 actions completed.
[FINE] freezed:freezed on test/graphql_responses/test_available_merchants.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/graphql_responses/test_general_responses.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/graphql_responses/test_merchant_menu.dart:Running FreezedGenerator
[INFO] Heartbeat:4.3s elapsed, 3/19 actions completed.
[INFO] Heartbeat:5.4s elapsed, 3/19 actions completed.
[INFO] Heartbeat:6.6s elapsed, 3/19 actions completed.
[INFO] Heartbeat:7.8s elapsed, 3/19 actions completed.
[INFO] Heartbeat:9.0s elapsed, 3/19 actions completed.
[INFO] Heartbeat:10.0s elapsed, 3/19 actions completed.
[INFO] Heartbeat:11.0s elapsed, 3/19 actions completed.
[INFO] Heartbeat:12.4s elapsed, 3/19 actions completed.
[INFO] Heartbeat:13.8s elapsed, 3/19 actions completed.
[INFO] Heartbeat:15.2s elapsed, 3/19 actions completed.
[INFO] Heartbeat:16.3s elapsed, 3/19 actions completed.
[INFO] Heartbeat:17.6s elapsed, 3/19 actions completed.
[WARNING] Heartbeat:
No actions completed for 15.0s, waiting on:
- freezed:freezed on test/database_integration_test.dart
- freezed:freezed on test/data_serialisation_tests/model_properties_test.dart
- freezed:freezed on test/data_serialisation_tests/model_converters_test.dart
- freezed:freezed on test/firebase_mock.dart
- freezed:freezed on test/delivery_dudes_gql_test.dart
.. and 11 more
[INFO] Heartbeat:18.9s elapsed, 3/19 actions completed.
[INFO] Heartbeat:19.9s elapsed, 3/19 actions completed.
[INFO] Heartbeat:21.0s elapsed, 3/19 actions completed.
[INFO] Heartbeat:22.1s elapsed, 3/19 actions completed.
[INFO] Heartbeat:23.1s elapsed, 3/19 actions completed.
FINE] freezed:freezed on test/data_serialisation_tests/model_properties_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/delivery_dudes_gql_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/algolia_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/delivery_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/firebase_mock.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/remote_config_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/stripe_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/card_helpers_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/discount_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/firebase_exception_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/authentication_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/api_integration_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/database_integration_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/cart_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/order_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/merchant_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/data_serialisation_tests/model_converters_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/search_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/push_notification_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/overlay_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/test_data.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/services_tests/user_service_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/test_helpers.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/graphql_parser_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/image_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/order_status_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/string_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/utils/time_helper_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/address_bottom_sheet_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/add_payment_method_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/address_details_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/add_card_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/address_selection_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/browse_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/change_password_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/checkouterror_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/checkout_waiting_room_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/checkout_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/delivery_bottom_sheet_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/create_profile_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/delivery_addresses_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/enroute_driver_banner_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/driver_tracking_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/favourites_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/forgot_password_confirmation_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/guest_mode_bottom_sheet_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/help_center_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/home_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/merchant_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/login_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/order_details_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/order_history_details_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/order_history_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/api/delivery_dudes_api.dart:Running FreezedGenerator
[FINE] freezed:freezed on test/viewmodel_tests/order_status_viewmodel_test.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/api/delivery_dudes_gql_api.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/api/graph_ql_parser.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/api/graph_ql_queries.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/app/flavor_config.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/app/lifecycle_manager.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/app/locator.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/app/logger.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/constants/app_constants.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/constants/app_strings.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/app/app.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/database/dddatabase.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/database/_fake_data.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/datamodels/application_models.dart:Running FreezedGenerator
[FINE] freezed:freezed on lib/datamodels/data_converters.dart:Running FreezedGenerator
...
NE] json_serializable:json_serializable on test/viewmodel_tests/browse_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/browse_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/change_password_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/change_password_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkouterror_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkouterror_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkout_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkout_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkout_waiting_room_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/checkout_waiting_room_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/create_profile_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/create_profile_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/delivery_addresses_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/delivery_addresses_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/delivery_bottom_sheet_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/delivery_bottom_sheet_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/driver_tracking_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/driver_tracking_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/enroute_driver_banner_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/enroute_driver_banner_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/favourites_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/favourites_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/forgot_password_confirmation_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/forgot_password_confirmation_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/guest_mode_bottom_sheet_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/guest_mode_bottom_sheet_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/help_center_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/help_center_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/home_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/home_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/login_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/login_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/merchant_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/merchant_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/order_details_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/order_details_viewmodel_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on test/viewmodel_tests/order_history_details_viewmodel_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on
[FINE] json_serializable:json_serializable on lib/constants/app_constants.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on lib/constants/app_strings.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/constants/app_strings.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on lib/database/dddatabase.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/database/dddatabase.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on lib/database/_fake_data.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/database/_fake_data.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on lib/datamodels/application_models.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/datamodels/data_converters.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/datamodels/data_converters.dart:Running JsonLiteralGenerator - 2 of 2
[SEVERE] json_serializable:json_serializable on lib/datamodels/application_models.dart:
Could not generate `toJson` code for `merchants` because of type `Merchant`.
package:customer_app/datamodels/application_models.freezed.dart:2174:24
╷
2174 │ final List<Merchant> merchants;
│ ^^^^^^^^^
╵
package:json_serializable/src/encoder_helper.dart 133:7 EncodeHelper._serializeField
package:json_serializable/src/encoder_helper.dart 59:42 EncodeHelper._writeToJsonSimple.<fn>
dart:core StringBuffer.writeAll
package:json_serializable/src/encoder_helper.dart 56:9 EncodeHelper._writeToJsonSimple
package:json_serializable/src/encoder_helper.dart 44:7 EncodeHelper.createToJson.sync_op
...
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/search/search_results.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/search/search_suggestions.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/search/search_view.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/search/search_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/select_previous_order_bottom_sheet/select_previous_order_bottom_sheet.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/shared/base_app_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/signup/signup_view.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/signup/signup_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/startup/startup_view.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/startup/startup_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/status_tracking_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/user_information/user_information_view.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/welcome/welcome_view.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/user_information/user_information_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/ui/views/welcome/welcome_viewmodel.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/card_helpers.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/discount_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/firebase_exception_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/image_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/map_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/order_status_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/platform_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/snackbar_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/util/time_helper.dart:Running StackedRouterGenerator
[FINE] stacked_generator:stackedRouterGenerator on lib/app/locator.config.dart:Running StackedRouterGenerator
[INFO] Build:Running build completed, took 2m 5s
[INFO] Build:Caching finalized dependency graph...
[INFO] Heartbeat:2m 6s elapsed, 3101/3101 actions completed.
[INFO] Build:Caching finalized dependency graph completed, took 1.2s
[SEVERE] Build:
Failed after 2m 6s
[+140810 ms] "flutter run" took 140 951ms.
[ +5 ms] pub finished with exit code 1
[ +35 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:364:7)
<asynchronous suspension>
#2 PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:238:5)
<asynchronous suspension>
#3 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
<asynchronous suspension>
#4 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
<asynchronous suspension>
#5 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#6 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#7 CommandRunner.runCommand (package:args/command_runner.dart:197:13)
<asynchronous suspension>
#8 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
<asynchronous suspension>
#9 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#10 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#11 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
<asynchronous suspension>
#12 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
<asynchronous suspension>
#13 run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
<asynchronous suspension>
#14 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#15 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#16 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
<asynchronous suspension>
#17 main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>
[ +364 ms] ensureAnalyticsSent: 252ms
[ +2 ms] Running shutdown hooks
[ +14 ms] Shutdown hooks complete
[ +2 ms] exiting with code 1
我希望能够生成我的模型代码,而不会得到已经定义的类型的类型错误。
我发现了问题所在。对于每个模型,我都有一些来自json逻辑的额外内容,我是这样写的。
factory Merchant.fromJson(Map<String, dynamic> incomingJson) {
var jsonPayload = Map<String, dynamic>.from(incomingJson);
if (jsonPayload['availableTimes'] is String) {
jsonPayload['availableTimes'] =
json.decode(jsonPayload['availableTimes']);
}
if (jsonPayload['territoryAvailableTimes'] is String) {
jsonPayload['territoryAvailableTimes'] =
json.decode(jsonPayload['territoryAvailableTimes']);
}
if (jsonPayload['cuisines'] is String) {
jsonPayload['cuisines'] = json.decode(jsonPayload['cuisines']);
}
return _$MerchantFromJson(jsonPayload).copyWith(
// Convert the bool to an integer and set it to the hideCustomizations value
hideCustomizations: boolToIntOrInt(jsonPayload['hideCustomizations']),
);
}
这导致生成器忽略json代码的生成。这是我从这条评论中发现的。所以我更新了Json函数中的所有自定义函数。
factory Merchant.fromJson(Map<String, dynamic> incomingJson) =>
_customFromJson(incomingJson);
static Merchant _customFromJson(Map<String, dynamic> incomingJson) {
var jsonPayload = Map<String, dynamic>.from(incomingJson);
if (jsonPayload['availableTimes'] is String) {
jsonPayload['availableTimes'] =
json.decode(jsonPayload['availableTimes']);
}
if (jsonPayload['territoryAvailableTimes'] is String) {
jsonPayload['territoryAvailableTimes'] =
json.decode(jsonPayload['territoryAvailableTimes']);
}
if (jsonPayload['cuisines'] is String) {
jsonPayload['cuisines'] = json.decode(jsonPayload['cuisines']);
}
if (jsonPayload['subVendors'] is String) {
jsonPayload['subVendors'] = json.decode(jsonPayload['subVendors']);
}
return _$MerchantFromJson(jsonPayload).copyWith(
// Convert the bool to an integer and set it to the hideCustomizations value
hideCustomizations: boolToIntOrInt(jsonPayload['hideCustomizations']),
);
}
重要的部分是确保fromJson函数具有=>
,否则由于某种原因它将被忽略。