Streambuilder отдельный виджет - PullRequest
0 голосов
/ 02 апреля 2020

Я ищу помощь с отдельным списком, а не блоком списка.

Это то, что мне нужно:

final List<Widget> items = _getitems();

 static List<Widget> _getitems() {
    List<Widget> result = new List();
    for (int i = 0; i <= 9; i++) {
      result.add(Container(
        padding: EdgeInsets.all(2.0),
        color: Colors.white,
        child: Text(
          '$i',
          style: TextStyle(fontSize: 22.0, color: Colors.black45),
        ),
      ));
    }
    return result;
  }

с Streambuilder, у меня блок только один виджет и мне нужен отдельный виджет. Я пытался добавить каждый контейнер, чтобы получить l oop streambuilder, но у меня возникла ошибка. Было выдано следующее исключение IntegerDivisionByZeroException:

  static List<Widget> _getitems() {
    final _bloc = BlocProvider.getBloc<FavoriteBloc>();
    List<Widget> result = new List();
    result.add(
      Container(
        child: StreamBuilder<Map<String, Item>>(
          stream: _bloc.outFav,
          initialData: {},
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return ListView(
                children: snapshot.data.values.map((i) {
                  return Container( //need to return only this container x 9
                    padding: EdgeInsets.all(2.0),
                    width: 97,
                    height: 50,
                    child: Image.network(i.thumb),
                  );
                }).toList(),
              );
            } else {
              return Container();
            }
          },
        ),
      ),
    );
print (result.length); //I have 1, I need 9
    return result;  
}
...