Horizontal ListView inside a Vertical ScrollView in Flutter

前端 未结 2 511
情歌与酒
情歌与酒 2021-01-30 04:45

I am trying to achieve a very common behavior nowadays which is to have a horizontal List within another widget which is at the same time scrollable. Think something like the ho

2条回答
  •  难免孤独
    2021-01-30 04:49

    Screenshot:


    class _HomePageState extends State {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: ListView.builder(
            itemCount: 7,
            itemBuilder: (_, i) {
              if (i < 2)
                return _buildBox(color: Colors.blue);
              else if (i == 3)
                return _horizontalListView();
              else
                return _buildBox(color: Colors.blue);
            },
          ),
        );
      }
    
      Widget _horizontalListView() {
        return SizedBox(
          height: 120,
          child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemBuilder: (_, __) => _buildBox(color: Colors.orange),
          ),
        );
      }
    
      Widget _buildBox({Color color}) => Container(margin: EdgeInsets.all(12), height: 100, width: 200, color: color);
    }
    

提交回复
热议问题