- Controller 被提前釋放
class ListWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final controller = Get.put(ListWidgetController());
return ListView.builder(
itemBuilder: ((context, index) => GetBuilder<ListWidgetController>(
id: index,
init: controller,
global: false,
builder: (controller) =>
...
Get.bottomSheet(ListWidget());
get 管理 controller 的生命周期颤霎,bottomSheet 彈出虐译,當(dāng) listView 滑到底部的時(shí)候會(huì)觸發(fā) Get 釋放 controller叉存,屬于偶發(fā)情況潜腻,當(dāng)列表不夠長(zhǎng)時(shí)不會(huì)觸發(fā)
[GETX] "ListWidgetController" onDelete() called
[GETX] "ListWidgetController" deleted from memory
- List<Widget> 元素類型問題
List<Widget> items = urls
.map(
(e) => FormFilePhotoItem(
e,
readonly: readonly,
onPressed: () => _onPressed(e),
onDelete: () => _onDelete(e),
),
)
.toList();
if (addable) {
items.add(FormFileAddItem(
onPressed: onAddItem,
));
}
// 報(bào)錯(cuò):
type 'FormFileAddItem' is not a subtype of type 'FormFilePhotoItem' of 'value'
items 雖是聲明為 List<Widget> 腻要,但實(shí)際上被初始化為 List<FormFilePhotoItem>
調(diào)整代碼如下:
List<Widget> items = [];
var photos = urls.map(
(e) => FormFilePhotoItem(
e,
readonly: readonly,
onPressed: () => _onPressed(e),
onDelete: () => _onDelete(e),
),
);
items.addAll(photos);
if (addable) {
items.add(FormFileAddItem(
onPressed: onAddItem,
));
}
- 使用 isolate時(shí)
E/flutter (28247): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message: (object extends NativeWrapper - Library:'dart:ui' Class: EngineLayer)
這是因?yàn)閭魅氲姆椒ú皇庆o態(tài)的,加上 static
即可