Flutter 如何使用Listview(可能是.builder)将滑块中的值显示为一行中的图标?

Flutter 如何使用Listview(可能是.builder)将滑块中的值显示为一行中的图标?,flutter,listview,slider,Flutter,Listview,Slider,现在,正如上面指出的,我正试图从一个滑块的值中给出一个视觉输出。申请表中的问题是:有多少人参加?然后应该有一个滑块,可以在2-20之间进行选择。根据您在上面滑动的方式,人数应显示为图标(Icons.people\u outline)。这应该很简单,我只是似乎经验不足。 这是代码片段: Column(children: <Widget>[ Container( height: 20, width: 100,

现在,正如上面指出的,我正试图从一个滑块的值中给出一个视觉输出。申请表中的问题是:有多少人参加?然后应该有一个滑块,可以在2-20之间进行选择。根据您在上面滑动的方式,人数应显示为图标(Icons.people\u outline)。这应该很简单,我只是似乎经验不足。 这是代码片段:

Column(children: <Widget>[
          Container(
            height: 20,
            width: 100,
            child: ListView.builder(
              itemCount: _currentSliderValue.round(),
                itemBuilder: (BuildContext context,int index){
                  return Icon(Icons.people_outline);
                }

            ),
          ),
          Text(_currentSliderValue.round().toString()),
          SingleChildScrollView(
            child: Slider(
              inactiveColor: Colors.white54,
              activeColor: Colors.white,
              value: _currentSliderValue,
              min: 2,
              max: 12,
              divisions: 10,
              label: _currentSliderValue.round().toString(),
              onChanged: (double value) {
                setState(() {
                  _currentSliderValue = value;
                });
              },
            ),
          ),
        ]),
列(子项:[
容器(
身高:20,
宽度:100,
子项:ListView.builder(
itemCount:_currentSliderValue.round(),
itemBuilder:(构建上下文,int索引){
返回图标(图标、人物轮廓);
}
),
),
文本(_currentSliderValue.round().toString()),
SingleChildScrollView(
子:滑块(
不活动颜色:颜色。白色54,
activeColor:Colors.white,
值:_currentSliderValue,
民:2,,
最高:12,
分部:10,
标签:_currentSliderValue.round().toString(),
一旦更改:(双值){
设置状态(){
_currentSliderValue=当前值;
});
},
),
),
]),
不知何故,图标没有显示出来。
谢谢你的任何想法!干杯

您的代码正常,您的列表正在显示,默认的滚动是垂直的,只需将:scrollDirection:Axis.horizontal添加到您的ListView中即可。 同时将容器宽度更改为宽度:double.infinity

      Container(
        height: 20,
        width: double.infinity,
        child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: _currentSliderValue.round(),
            itemBuilder: (context, index) {
              return Icon(
                Icons.people_outline,
                color: Colors.red,
              );
            }),
      ),