Update guidance around dart:ffi in widget previews#89
Conversation
`dart:ffi` imports in transitive dependencies used to prevent the widget previewer from compiling, but this was resolved in Flutter 3.41. This change updates the guidance around `dart:ffi` to match that of `dart:io`, as `dart:ffi` APIs will now throw on invocation in the widget previewer.
There was a problem hiding this comment.
Code Review
This pull request updates the documentation in SKILL.md regarding the use of native APIs in the Flutter Widget Previewer. The review suggests clarifying that while transitive dependencies on dart:io or dart:ffi no longer prevent compilation, invoking these APIs will still cause exceptions, and provides a more precise phrasing for the documentation.
| Adhere to the following constraints when authoring previewable widgets, as the Widget Previewer runs in a web environment: | ||
|
|
||
| - **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. Widgets with transitive dependencies on `dart:io` will throw exceptions upon invocation, and `dart:ffi` dependencies will fail to load. Use conditional imports to mock or bypass these in preview mode. | ||
| - **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. Widgets with transitive dependencies on `dart:io` or `dart:ffi` will throw exceptions upon invocation. Use conditional imports to mock or bypass these in preview mode. |
There was a problem hiding this comment.
The updated wording suggests that any widget with a transitive dependency on dart:io or dart:ffi will throw an exception upon invocation. It is clearer to specify that the exception occurs when the APIs are invoked. Additionally, since the primary change (resolved in Flutter 3.41) is that these dependencies no longer prevent compilation, explicitly mentioning this improvement provides valuable context for developers who may have previously avoided these libraries.
| - **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. Widgets with transitive dependencies on `dart:io` or `dart:ffi` will throw exceptions upon invocation. Use conditional imports to mock or bypass these in preview mode. | |
| - **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. While transitive dependencies on these libraries no longer prevent compilation, invoking their APIs will throw exceptions in the previewer. Use conditional imports to mock or bypass these in preview mode. |
|
@bkonyi Since this skill is grounded in our docs, this indicates an issue we need to fix on the widget previewer docs page: flutter/website#13306 |
See flutter/skills#89 for details --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
dart:ffiimports in transitive dependencies used to prevent the widget previewer from compiling, but this was resolved in Flutter 3.41.This change updates the guidance around
dart:ffito match that ofdart:io, asdart:ffiAPIs will now throw on invocation in the widget previewer.