4个水平列表视图颤振

时间:2020-10-23 08:14:19

标签: android flutter listview dart android-listview

我想使用4 listView Builder,它可以在SingleChildScrollView中水平滚动,但是即使尝试了所有内容后页面仍不能垂直滚动,任何人都可以帮我解决这个问题。 例子:

@override
 Widget build(BuildContext context) {
   return FutureBuilder(
     future: getLibrayCourse(),
     builder:  (context,snapshot){
       if(snapshot.connectionState==ConnectionState.waiting){
         return Center(child: CircularProgressIndicator());
       }
       return Container(
         padding: EdgeInsets.all(20),
         child: Column(
           mainAxisAlignment: MainAxisAlignment.start,
           crossAxisAlignment: CrossAxisAlignment.start,
           children: [
             Text("Free Video Courses",style: TextStyle(
               fontWeight: FontWeight.bold,
               fontSize: 18
             ),),
             SizedBox(height:10),
             Container(
               height: MediaQuery.of(context).size.height/4,
               child: ListView.builder(
                   scrollDirection: Axis.horizontal,
                   shrinkWrap: true,
                   itemCount: 10,
                   itemBuilder: (context, index){
                     return Card(
                       child: Text("YOYO"),
                     );
                   }),
             ),
             Text("Free Video Courses",style: TextStyle(
                 fontWeight: FontWeight.bold,
                 fontSize: 18
             ),),
             SizedBox(height:10),
             Container(
               height: MediaQuery.of(context).size.height/4,
               child: ListView.builder(
                   scrollDirection: Axis.horizontal,
                   shrinkWrap: true,
                   itemCount: 10,
                   itemBuilder: (context, index){
                     return Card(
                       child: Text("YOYO"),
                     );
                   }),
             ),
             Text("Free Video Courses",style: TextStyle(
                 fontWeight: FontWeight.bold,
                 fontSize: 18
             ),),
             SizedBox(height:10),
             Container(
               height: MediaQuery.of(context).size.height/4,
               child: ListView.builder(
                   scrollDirection: Axis.horizontal,
                   shrinkWrap: true,
                   itemCount: 10,
                   itemBuilder: (context, index){
                     return Card(
                       child: Text("YOYO"),
                     );
                   }),
             ),
             Text("Free Video Courses",style: TextStyle(
                 fontWeight: FontWeight.bold,
                 fontSize: 18
             ),),
             SizedBox(height:10),
             Container(
               height: MediaQuery.of(context).size.height/4,
               child: ListView.builder(
                   scrollDirection: Axis.horizontal,
                   shrinkWrap: true,
                   itemCount: 10,
                   itemBuilder: (context, index){
                     return Card(
                       child: Text("YOYO"),
                     );
                   }),
             ),

           ],
         ),
       );
     },
   );
 }

如果我在水平窗口小部件中使用Neverscrollable,它将停止滚动,所以这是一个问题 我尝试添加容器高度,使用扩展等仍然存在问题

1 个答案:

答案 0 :(得分:0)

我复制并使用了您的代码,然后将“列”移到了“ SingleChildScrollView”。水平滚动和垂直滚动都对我有用。

@override
  Widget build(BuildContext context) {
    return FutureBuilder(
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Center(child: CircularProgressIndicator());
        }
        return Container(
          padding: EdgeInsets.all(20),
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // your children
              ]
            ),
          ),
        );
      },
    );
  }

我希望它对您有用。