问题杂记

  1. Controller 被提前释放
class ListWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
     final controller = Get.put(ListWidgetController());
     return ListView.builder(
            itemBuilder: ((context, index) => GetBuilder(
                id: index,
                init: controller,
                global: false,
                builder: (controller) =>
...

Get.bottomSheet(ListWidget());

get 管理 controller 的生命周期,bottomSheet 弹出,当 listView 滑到底部的时候会触发 Get 释放 controller,属于偶发情况,当列表不够长时不会触发

[GETX] "ListWidgetController" onDelete() called
[GETX] "ListWidgetController" deleted from memory
  1. List 元素类型问题
    List items = urls
        .map(
          (e) => FormFilePhotoItem(
            e,
            readonly: readonly,
            onPressed: () => _onPressed(e),
            onDelete: () => _onDelete(e),
          ),
        )
        .toList();
    if (addable) {
      items.add(FormFileAddItem(
        onPressed: onAddItem,
      ));
    }
// 报错:
type 'FormFileAddItem' is not a subtype of type 'FormFilePhotoItem' of 'value'

items 虽是声明为 List ,但实际上被初始化为 List
调整代码如下:

    List 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,
      ));
    }
  1. 使用 isolate时
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)

这是因为传入的方法不是静态的,加上 static 即可

你可能感兴趣的:(问题杂记)