简体   繁体   English

如何使 ListView Items 在容器底部以固定高度对齐而不在 Flutter 中使用反向?

[英]How to make ListView Items align at bottom of a container with a fixed height without using reverse in Flutter?

In my Flutter project, I have a container with a fixed height.在我的 Flutter 项目中,我有一个高度固定的容器 Inside that container I have a Listview .在那个容器内,我有一个Listview

Here's the code-这是代码-

return new Scaffold(

  appBar: AppBar(
    title: Text("All Values"),
  ),

  body: new Column(
    crossAxisAlignment: CrossAxisAlignment.end,
    children: <Widget>[

      Container(
        height: isLoading ? 50.0 : 0,
        color: Colors.white70,
        child: Center(
          child: new CircularProgressIndicator(),
        ),
      ),

      Expanded(
        child: Container(
          height: 350,
          color: Colors.red,
          alignment: Alignment.bottomLeft,

          child:
          new ListView.builder(
            itemCount: data.length-8,

            itemBuilder: (BuildContext cxtx, int index) {
              return Padding(
                padding:  const EdgeInsets.fromLTRB(10, 0.0, 10, 0),
                child: Container(
                  child: showCard(index, radius),
                ),
              );

            },

            controller: _scrollController,
          ),

        ),),

    ],
  ),

  resizeToAvoidBottomPadding: false,

);

The code outputs like below-代码输出如下-

在此处输入图片说明

So, the problem is I want to align these items at bottom left of the container.所以,问题是我想在容器的左下角对齐这些项目。 I could have done that using reverse: true but I need the list items with the same sequence.我可以使用reverse: true做到这一点,但我需要具有相同序列的列表项。 So, I need suggestion how can I do that?所以,我需要建议我该怎么做?

You need those items in a row or a column?您需要一行或一列中的这些项目吗? Follow with a row possibility: Try this:跟随一个行的可能性:试试这个:

 return new Scaffold(
  appBar: AppBar(
    title: Text("All Values"),
  ),
  body:  Column(
    mainAxisSize: MainAxisSize.max,
    mainAxisAlignment: MainAxisAlignment.end,
    children: <Widget>[
      if(isLoading)
        Container(
        height: 50.0 ,
        color: Colors.white70,
        child: Center(
          child: new CircularProgressIndicator(),
        ),
      ),
      Expanded(
        child: Container(
          height: 350,
          color: Colors.red,
          alignment: Alignment.bottomLeft,
          child: new ListView.builder(
            itemCount: data.length - 8,
            itemBuilder: (BuildContext cxtx, int index) {
              return Padding(
                padding: const EdgeInsets.fromLTRB(10, 0.0, 10, 0),
                child: Container(
                  child: Text('asdf'),
                ),
              );
            },
            controller: _scrollController,
          ),
        ),
      ),
    ],
  ),
  resizeToAvoidBottomPadding: false,
);
StoreConnector<_ViewModel, List<Message>>(
      converter: (store) {
        // check mark ,reverse data list
        if (isReverse) return store.state.dialogList;
        return store.state.dialogList.reversed.toList();
      },
      builder: (context, dialogs) {
        // Add a callback when UI render after. then change it direction;
        WidgetsBinding.instance.addPostFrameCallback((t) {
          // check it's items could be scroll
          bool newMark = _listViewController.position.maxScrollExtent > 0;
          if (isReverse != newMark) { // need 
            isReverse = newMark;  // rebuild listview
            setState(() {});
          }
        });

        return ListView.builder(
          reverse: isReverse, // 反转列表,insert数据时,刷新到0,加载更多时,滚动偏移不变
          controller: _listViewController,
          itemBuilder: (context, index) => _bubbleItem(context, dialogs[index], index),
          itemCount: dialogs.length,
        );
      },
    )

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

相关问题 如何在不使用 Flutter 中的底部导航栏的情况下显示固定在屏幕底部的 Container? - How to show a Container fixed at bottom of screen without using bottom navigation bar in Flutter? Flutter 如何根据 ListView 项目高度更改容器高度? - Flutter How to change container height based on the ListView items height? 如何在 Flutter 中不设置容器高度的情况下在容器内显示 ListView? - How to display ListView inside a Container without setting Container height in Flutter? 如何在 Flutter 中不给出固定高度的情况下在 ListView 中显示卡片? - How to display card in ListView without giving a fixed height in Flutter? 如何在列表视图中对齐底部容器? - How to align bottom container inside listview? 如何将固定到底部的容器添加到条子 flutter - how to add a fixed to bottom container to a sliver flutter 如何使容器高度动态以适应 ListView 但达到一定的最大高度 Flutter - How to make Container height dynamic to fit ListView but to certain max height Flutter 如何在抖动中制作底部固定视图 - How to make bottom fixed view in flutter 有没有办法将一列放在一个单子视图中而不放在一个固定高度的容器中? flutter - Is there a way to put a column in a singlechildview without putting in a container with fixed height? flutter Container 中的固定高度在 Flutter 中不起作用 - Fixed height in Container is not working in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM