how to create a row of scrollable text boxes or widgets in flutter inside a ListView?

前端 未结 6 1064
悲哀的现实
悲哀的现实 2021-01-01 11:46

1.Please, can someone tell me how to create a row of text boxes that are scrollable to left or right in flutter inside a ListView. I can see that I am trying to define an in

6条回答
  •  有刺的猬
    2021-01-01 12:06

    You can use:

    @override
    Widget build(BuildContext context) {
      return Column(
        children: [
          SizedBox( // Horizontal ListView
            height: 100,
            child: ListView.builder(
              itemCount: 20,
              scrollDirection: Axis.horizontal,
              itemBuilder: (context, index) {
                return Container(
                  width: 100,
                  alignment: Alignment.center,
                  color: Colors.blue[(index % 9) * 100],
                  child: Text(index.toString()),
                );
              },
            ),
          ),
          SizedBox( // Vertical ListView
            height: 200,
            child: ListView.builder(
              itemCount: 20,
              itemBuilder: (context, index) {
                return Container(
                  width: 50,
                  height: 50,
                  alignment: Alignment.center,
                  color: Colors.orange[(index % 9) * 100],
                  child: Text(index.toString()),
                );
              },
            ),
          ),
        ],
      );
    }
    

    Note: For simplicity I didn't refactor the two ListView in a single Widget

    Output

提交回复
热议问题