mapListenable method

List<Widget> mapListenable(
  1. Widget? callback(
    1. T item
    )
)

Convert each Listenable element to a Widget via callback.

Wrapping the conversion with a ListenableListener will update the Widget when notified of changes to the given Listenable.

When the contents of a DocumentBase contained in a CollectionBase are changed, CollectionBase will not receive a change notification (unless the number of elements in the CollectionBase is changed).

By using this method to expand the contents, even if the contents of DocumentBase are changed, it is possible to receive a change notification and reflect the changes only in the relevant contents.

Listenable要素をcallbackを介してWidgetに変換します。

変換する際にListenableListenerでラップすることで、与えられたListenableの変更が通知された際にWidgetを更新します。

CollectionBaseに含まれるDocumentBaseの内容が変更される際、(CollectionBaseの要素数が変更される場合を除いて)CollectionBaseには変更通知は届きません。

このメソッドで中身を展開することでDocumentBaseの内容が変更された場合でも変更通知を受け取り該当する中身のみ変更内容を反映することが可能になります。

Implementation

List<Widget> mapListenable(Widget? Function(T item) callback) {
  return map((item) {
    return ListenableListener<T>(
      listenable: item,
      builder: (context, listenable) => listenable == null
          ? const SizedBox.shrink()
          : callback.call(listenable) ?? const SizedBox.shrink(),
    );
  }).toList();
}