toProviderList method

List<Widget> toProviderList({
  1. Widget? child,
  2. Widget builder(
    1. BuildContext context,
    2. int index,
    3. T state
    )?,
})

Converts this into a list of Providers that provide the elements of this with a child or a builder.

To use this method you must depend on this EmitterList's parent in the build method in which this method is called or your app may display incorrect state.

Implementation

List<Widget> toProviderList(
    {Widget? child,
    Widget Function(BuildContext context, int index, T state)? builder}) {
  assert((child == null && builder != null) ||
      (child != null && builder == null));
  return [
    for (var i = 0; i < length; i++)
      Provider<T>(
        state: this[i],
        child: child,
        builder: builder != null ? (c, s) => builder(c, i, s) : null,
      )
  ];
}