gpt4 book ai didi

Dart 对象到 native - UnimplementedError : structured clone of other type

转载 作者:行者123 更新时间:2023-12-03 02:57:11 26 4
gpt4 key购买 nike

将 dart web 应用程序与浏览器历史记录集成,我想将 dart 对象推送到 window.history堆。

Dart 对象。

class AppState {
final int index;

AppState(this.index){
}
}

api
https://api.dartlang.org/stable/1.15.0/dart-html/History/pushState.html

它适用于例如一个 Map toMap()方法,以及匹配的工厂构造函数,但这是蛮力方式。仅仅依靠dart框架就给出了下面的stackdump,表示 AppState错过了一些序列化方法。有谁知道是哪个?
Uncaught Unhandled exception:
UnimplementedError: structured clone of other type
#0 _StructuredClone.walk (file:///mnt/data/b/build/slave/dartium-lucid64-full-stable/build/src/dart/sdk/lib/html/html_common/conversions.dart:136)
#1 _StructuredClone.convertDartToNative_PrepareForStructuredClone (file:///mnt/data/b/build/slave/dartium-lucid64-full-stable/build/src/dart/sdk/lib/html/html_common/conversions.dart:151)
#2 convertDartToNative_PrepareForStructuredClone (file:///mnt/data/b/build/slave/dartium-lucid64-full-stable/build/src/dart/sdk/lib/html/html_common/conversions_dartium.dart:4)
#3 convertDartToNative_SerializedScriptValue (file:///mnt/data/b/build/slave/dartium-lucid64-full-stable/build/src/dart/sdk/lib/html/html_common/conversions.dart:33)
#4 History.pushState (dart:html:19793)
#5 AppHistoryCtrl.pushState (package:mintest/app_history_ctrl.dart:35:20)

最佳答案

这就是应该发生的事情。为了进入历史,它通过指定的结构化克隆算法进行序列化。那不知道如何处理任意 Dart 对象。例如,如果我们以这种方式将某些东西插入历史,一些 JavaScript 代码可能会将其取出,并且无法处理任意 Dart 对象。所以是的,它需要转换成 Map,或者结构化克隆算法可以理解的其他结构。

关于Dart 对象到 native - UnimplementedError : structured clone of other type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com