This commit is contained in:
Xingwei Zhu 2021-04-23 17:31:47 +08:00
Родитель 7eedebbe2d
Коммит 5fed0301ce
2 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -203,6 +203,18 @@ UIWidgets也支持Gif
如果想在runtime选择是否debug请修改文件```com.unity.uiwidgets/com.unity.uiwidgets/Runtime/foundation/debug.cs```中的```static bool debugEnableAtRuntimeInternal```
## 使用Window Scope保护外部调用
如果您在调试时遇到 `AssertionError: Window.instance is null` 或者在调用 `Window.instance` 时得到空指针, 那么您需要
使用以下方式来保护您的调用使之可以在正确的Isolate上执行回调逻辑
```csharp
using(Isolate.getScope(the isolate of your App)) {
// code dealing with UIWidgets,
// e.g. setState(() => {....})
}
```
通常在您使用外部事件例如来自UIWidgets之外的输入事件、网络传输回调事件时需要做这样的处理。具体的您可以参考我们的 HttpRequestSample 这个样例中的写法。需要注意的是一般情况下您在UIWidgets框架的内部调用 (如 `Widget.build, State.initState...`)中不需要额外采取上述保护措施。
## 学习
#### 教程

Просмотреть файл

@ -213,6 +213,24 @@ In Unity editor, you can switch debug/release mode by “UIWidgets->EnableDebug
If you want to change different mode in runtime, please modify the file “com.unity.uiwidgets/com.unity.uiwidgets/Runtime/foundation/debug.cs” by making “static bool debugEnableAtRuntimeInternal” to true or false. Note that the value is set to false by default.
## Using Window Scope
If you see the error `AssertionError: Window.instance is null` or null pointer error of `Window.instance`,
it means the code is not running in the window scope. In this case, you can enclose your code
with window scope as below:
```csharp
using(Isolate.getScope(the isolate of your App)) {
// code dealing with UIWidgets,
// e.g. setState(() => {....})
}
```
This is needed if the code is in methods
not invoked by UIWidgets. For example, if the code is in `completed` callback of `UnityWebRequest`,
you need to enclose them with window scope.
Please see our HttpRequestSample for detail.
For callback/event handler methods from UIWidgets (e.g `Widget.build, State.initState...`), you don't need do
it yourself, since the framework ensure it's in window scope.
## Learn
#### Samples