简体   繁体   English

ListView.separated 未在 flutter 中构建

[英]ListView.separated is not building in flutter

here is the code of my screen, and in this screen i'm trying to build a list view.这是我的屏幕代码,在这个屏幕上我试图建立一个列表视图。

Container(
      decoration: const BoxDecoration(gradient: kHomeColor),
      child: Column(
        children: [
          const AccountCard(
            name: 'Mishal Haneef',
            channelName: 'MSL DROID',
            courseCount: '3',
            subscribers: '65K',
          ),
          ListView.separated(
            
            itemBuilder: (BuildContext context, int index) {
              print('entered  to itemBuilder');
              return const ListTile(
                title: Text('data $index'),
                leading: Icon(Icons.abc),
                trailing: Icon(Icons.arrow_left),
              );
            },
            itemCount: 3,
            separatorBuilder: (BuildContext context, int index) {
              return const Divider();
            },
          )
        ],
      ),
    );

and this is not working showing this error这无法显示此错误

#46     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
The following RenderObject was being processed when the exception was fired: RenderViewport#3884a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderViewport#3884a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    needs compositing
    parentData: <none> (can use size)
    constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=Infinity)
    size: MISSING
    axisDirection: down
    crossAxisDirection: right
    offset: ScrollPositionWithSingleContext#f3aae(offset: 0.0, range: null..null, viewport: null, ScrollableState, AlwaysScrollableScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#7e5b2, ScrollDirection.idle)
    anchor: 0.0
    center child: RenderSliverPadding#8e8d0 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: paintOffset=Offset(0.0, 0.0)
        constraints: MISSING
        geometry: null
        padding: EdgeInsets(0.0, 24.0, 0.0, 0.0)
        textDirection: ltr
        child: RenderSliverList#29eb9 NEEDS-LAYOUT NEEDS-PAINT
            parentData: paintOffset=Offset(0.0, 0.0)
            constraints: MISSING
            geometry: null
            no children current live

i don't get it what they are saying and showing a erroe log that relevent error cause this widget (showing all widget name from scaffold to list view), why is this happening, and how can i fix this,我不明白他们在说什么,并显示错误日志,相关错误导致此小部件(显示从脚手架到列表视图的所有小部件名称),为什么会发生这种情况,我该如何解决,

Just wrap the ListView.separated with Expanded Widget like the below one:只需将ListView.separatedExpanded Widget 包装起来,如下所示:

Container(
   decoration: const BoxDecoration(gradient: kHomeColor),
   child: Column(
      children: [
         const AccountCard(
           name: 'Mishal Haneef',
           channelName: 'MSL DROID',
           courseCount: '3',
           subscribers: '65K',
         ),
         Expanded(
              child: ListView.separated(
                itemBuilder: (BuildContext context, int index) {
                  print('entered  to itemBuilder');
                  return ListTile(
                    title: Text('data $index'),
                    leading: Icon(Icons.block),
                    trailing: Icon(Icons.arrow_left),
                  );
                },
                itemCount: 3,
                separatorBuilder: (BuildContext context, int index) {
                  return const Divider();
                },
              ),
            ),
          ],
      ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM